Opentelemetry——Signals-Logs

2024-05-24 19:25:11 浏览数 (2)

大纲
  • *Logs*
    • *Log Appender / Bridge*
      • *Logger Provider*
      • *Logger*
    • *Log Record Exporter*
    • *Log Record*
  • *Language Support*
  • *Specification*

Logs

A log is a timestamped text record, either structured (recommended) or unstructured, with metadata. Of all telemetry signals, logs have the biggest legacy. Most programming languages have built-in logging capabilities or well-known, widely used logging libraries. Although logs are an independent data source, they may also be attached to spans. In OpenTelemetry, any data that is not part of a distributed trace or a metric is a log. For example, events are a specific type of log. Logs often contain detailed debugging/diagnostic info, such as inputs to an operation, the result of the operation, and any supporting metadata for that operation. Log是带时间戳的文本记录,可以是结构化(推荐)或非结构化,带有元数据。在所有遥测信号中,Log具有最多的历史资产。大多数编程语言都具有内置的Log功能或知名的、被广泛使用的Log库。虽然Log是独立的数据源,但它们也可能附加到Span上。在 OpenTelemetry中,任何不属于分布式Trace或Metric的数据都是Log。例如,事件是一种特定类型的Log。Log通常包含详细的调试/诊断信息,例如操作的输入、操作的结果以及表达该操作的任何元数据。

For traces and metrics, OpenTelemetry takes the approach of a clean-sheet design, specifies a new API, and provides full implementations of this API in multiple language SDKs. 对于Trace和Metrics,OpenTelemetry采用了全新的设计方法,指定了新的 API,并在多种编程语言的SDK中提供了该API的完整实现。

OpenTelemetry’s approach with logs is different. Because existing logging solutions are widespread in language and operational ecosystems, OpenTelemetry acts as a “bridge” between those logs, the tracing and metrics signals, and other OpenTelemetry components. In fact, the API for logs is called the “Logs Bridge API” for this reason. OpenTelemetry处理Log的方法有所不同。由于现有的Log解决方案在语言和操作生态系统中广泛存在,因此OpenTelemetry只用充当将这些Log、Trace、Metric信号和其他OpenTelemetry组件连接的“桥梁”。事实上,出于这个原因,Log API 被称为“Logs Bridge API”。

The logs specification contains more details on this philosophy. Logs规范包含有关此概念的更多详细信息。

To understand how logging in OpenTelemetry works, let’s look at a list of components that will play a part in instrumenting our code. 为了了解 OpenTelemetry 中的Log如何工作,让我们看一下在我们代码中发挥作用的测量组件列表。

Log Appender / Bridge

As an application developer, the Logs Bridge API should not be called by you directly, as it is provided for logging library authors to build log appenders / bridges. Instead, you just use your preferred logging library and configure it to use a log appender (or log bridge) that is able to emit logs into an OpenTelemetry LogRecordExporter. 作为应用程序开发人员,您不应直接调用Logs Bridge API ,因为它是为Log库作者提供的,用于构建Log Appender / Bridge。相反,您只需使用您喜欢的Log库,并将其配置成可以将Log发送到 OpenTelemetry LogRecordExporter 的Log Appender / Bridge即可。

OpenTelemetry language SDKs offer this functionality. OpenTelemetry的语言SDK 提供此功能。

Logger Provider

Part of the Logs Bridge API and should only be used if you are the author of a logging library.

Log Appender / Bridge的一部分,仅当您是Log库的作者时才应使用。

A Logger Provider (sometimes called LoggerProvider) is a factory for Loggers. In most cases, the Logger Provider is initialized once and its lifecycle matches the application’s lifecycle. Logger Provider initialization also includes Resource and Exporter initialization. Logger Provider(有时称为LoggerProvider)是创建Logger的工厂。在大多数情况下,Logger Provider只会初始化一次,并且其生命周期与应用程序的生命周期相匹配。Logger Provider初始化还包括Resource和Exporter初始化。

Logger

Part of the Logs Bridge API and should only be used if you are the author of a logging library.

Log Appender / Bridge的一部分,仅当您是Log库的作者时才应使用。

A Logger creates log records. Loggers are created from Log Providers. Logger创建Log Records。Logger是从Logger Provider创建的。

Log Record Exporter

Log Record Exporters send log records to a consumer. This consumer can be standard output for debugging and development-time, the OpenTelemetry Collector, or any open source or vendor backend of your choice. Log Record Exporter将Log Records发送给消费者。该消费者可以是用于调试和开发时的标准输出、OpenTelemetry Collector 或您选择的任何开源或供应商后端。

Log Record

A log record represents the recording of an event. In OpenTelemetry a log record contains two kinds of fields: Log Record表示事件的记录。在OpenTelemetry中,Log Record包含两种字段:

  • Named top-level fields of specific type and meaning 特定类型和含义的顶级具名字段
  • Resource and attributes fields of arbitrary value and type 任意值和类型的资源和属性字段

The top-level fields are: 顶级字段是:

Field Name

Description

Timestamp

事件发生的时间。

ObservedTimestamp

观测事件的时间。

TraceId

请求的 Trace ID.

SpanId

请求的 Span ID.

TraceFlags

W3C trace flag.

SeverityText

严重性文本(也称为Log级别)。

SeverityNumber

严重性的数值。

Body

Log记录的正文。

Resource

描述Log的来源。

InstrumentationScope

描述发出Log的范围。

Attributes

有关该事件的其他信息。

For more details on log records and log fields, see Logs Data Model. 有关Log Records和Log字段的更多详细信息,请参阅 Logs Data Model.。

Language Support

Logs are a stable signal in the OpenTelemetry specification. For the individual language specific implementations of the Logs API & SDK, the status is as follows: Logs是OpenTelemetry 规范中的稳定信号。对于Log API 和 SDK 的各个语言特定实现,情况如下:

Language

Logs

C

Stable

C#/.NET

Stable

Erlang/Elixir

Experimental

Go

In development

Java

Stable

JavaScript

Experimental

PHP

Stable

Python

Experimental

Ruby

In development

Rust

Alpha

Swift

In development

Specification

To learn more about logs in OpenTelemetry, see the logs specification.

0 人点赞