0Pricing
System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) · 강의

OpenTelemetry SDK로 애플리케이션 계측

다양한 프로그래밍 언어를 위한 OpenTelemetry SDK를 개괄적으로 살펴봅니다. SDK를 사용해 로그, 지표, 추적을 생성하는 방법을 이해합니다.

OpenTelemetry SDK로 애플리케이션 계측은(는) CoddyKit의 무료 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

What are OTel SDKs?

OpenTelemetry SDKs are language-specific libraries that enable your applications to generate and export observability data. Think of them as the toolkit for making your code observable.

They provide the necessary APIs (Application Programming Interfaces) to capture logs, metrics, and traces directly from your application's runtime.

Role of OpenTelemetry SDKs

SDKs are crucial because they bridge the gap between your application code and the OpenTelemetry standard. They handle the complex work of:

  • Collecting Data: Gathering raw observability signals like method calls or variable values.
  • Processing Data: Enriching, filtering, and batching this data.
  • Exporting Data: Sending the processed data to an observability backend (like Jaeger, Prometheus, or an ELK stack).

Key OTel SDK Components

An OpenTelemetry SDK typically includes several core components that work together:

  • Providers: Such as TracerProvider, MeterProvider, and LoggerProvider, which manage the creation of Tracers, Meters, and Loggers.
  • Processors/Readers: These define how collected data (spans, metrics, log records) is processed before being sent to an exporter.
  • Exporters: Components that send the processed data to an external system, like a console or a remote endpoint.

Tracing with OTel SDKs

When you want to trace requests through your system, OpenTelemetry SDKs provide tools to create and manage spans. A span represents a single operation within a trace.

The SDK gives you a Tracer object, which you use to start new spans, set attributes on them, and link them to parent spans, effectively building a complete trace of a request's journey.

OTel Tracing Code Example

Here's a simple Python example showing how to initialize OpenTelemetry and create a basic trace with nested spans. We use a ConsoleSpanExporter to print spans to the console.

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor

# 1. Configure the TracerProvider
provider = TracerProvider()
processor = SimpleSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)

# 2. Get a Tracer
tracer = trace.get_tracer(__name__)

# 3. Create a Span
with tracer.start_as_current_span("my-first-span"):
    print("Inside the span!")
    with tracer.start_as_current_span("child-span"):
        print("Inside the child span!")

print("Tracing example finished.")

Metrics with OTel SDKs

OpenTelemetry SDKs allow you to define and record various types of metrics. Metrics are numerical measurements captured over time, useful for aggregated views of system health and performance.

You obtain a Meter object from the SDK, which you then use to create different types of instruments, such as Counters (for incrementing values) or Gauges (for current values).

OTel Metrics Code Example

This Python example demonstrates how to set up OpenTelemetry for metrics and use a Meter to create and update a Counter. The ConsoleMetricExporter prints the collected metrics.

from opentelemetry import metrics
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import ConsoleMetricExporter, PeriodicExportingMetricReader

# 1. Configure the MeterProvider
reader = PeriodicExportingMetricReader(ConsoleMetricExporter())
provider = MeterProvider(metric_readers=[reader])
metrics.set_meter_provider(provider)

# 2. Get a Meter
meter = metrics.get_meter(__name__)

# 3. Create a Counter instrument
counter = meter.create_counter(
    "my_example_counter",
    description="Counts how many times something happens"
)

# 4. Record a measurement
counter.add(1, {"key": "value"})
counter.add(2, {"another_key": "another_value"})
print("Metrics example finished. May take a moment to export.")

Logging with OTel SDKs

OpenTelemetry SDKs also provide a way to capture and enrich logs. While traditional logging often focuses on plain text, OTel logs can be structured and correlated with traces and metrics.

The SDK offers a Logger (or integrates with existing logging frameworks) to create Log Records. These records can then be processed and exported alongside your traces and metrics, providing a unified view.

OTel Logging Code Example

This Python example shows how to integrate OpenTelemetry with the standard Python logging library. Logs emitted through the standard logger are then processed and exported by OTel.

import logging
from opentelemetry._logs import set_logger_provider
from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler
from opentelemetry.sdk._logs.export import ConsoleLogExporter, SimpleLogRecordProcessor

# 1. Configure the LoggerProvider
provider = LoggerProvider()
processor = SimpleLogRecordProcessor(ConsoleLogExporter())
provider.add_log_record_processor(processor)
set_logger_provider(provider)

# 2. Get a Python standard logger
#    and attach the OTel handler
handler = LoggingHandler(logger_provider=provider)
logging.getLogger().addHandler(handler)
logging.getLogger().setLevel(logging.INFO)

# 3. Emit a log record
logging.info("This is an info log from OTel SDK!")
logging.warning("A warning occurred.")

print("Logging example finished.")

OTel SDKs Quick Check

OpenTelemetry SDKs are essential for instrumenting applications. Which of the following is NOT a core component or function provided by an OpenTelemetry SDK?

Recap: OTel SDKs

You've learned that OpenTelemetry SDKs are the foundational tools for instrumenting your applications across different programming languages.

  • They provide the APIs to generate traces, metrics, and logs.
  • They handle the processing and exporting of this data to your chosen observability backend.
  • By using SDKs, you ensure your application's observability data adheres to the OpenTelemetry standard, making it portable and vendor-agnostic.

Next, you'll dive deeper into how to effectively instrument your applications.

자주 묻는 질문

“OpenTelemetry SDK로 애플리케이션 계측” 강의는 무료인가요?

네 — “OpenTelemetry SDK로 애플리케이션 계측” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 강의 전체를 잠금 해제할 수 있습니다. System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 강의에는 총 4개의 강의가 포함되어 있습니다.

“OpenTelemetry SDK로 애플리케이션 계측”에서 뭘 배우나요?

다양한 프로그래밍 언어를 위한 OpenTelemetry SDK를 개괄적으로 살펴봅니다. SDK를 사용해 로그, 지표, 추적을 생성하는 방법을 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“OpenTelemetry SDK로 애플리케이션 계측” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. OpenTelemetry 표준
  2. OpenTelemetry 수집기와 내보내기 도구
  3. OpenTelemetry SDK로 애플리케이션 계측
  4. 신호와 의미 규약
← System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)(으)로 돌아가기