Overview

Datadog tracing libraries provide an implementation of the OpenTelemetry API for instrumenting your code. This means you can maintain vendor-neutral instrumentation of all your services, while still taking advantage of Datadog’s native implementation, features, and products. You can configure it to generate Datadog-style spans and traces to be processed by the Datadog tracing library for your language, and send those to Datadog.

By instrumenting your code with OpenTelemetry API:

  • Your code remains free of vendor-specific API calls.
  • Your code does not depend on Datadog tracing libraries at compile time (only runtime).
  • Your code does not use the deprecated OpenTracing API.

Replace the OpenTelemetry SDK with the Datadog tracing library in the instrumented application, and the traces produced by your running code can be processed, analyzed, and monitored alongside Datadog traces and in Datadog proprietary products.

For more information, read Interoperability of OpenTelemetry API and Datadog instrumented traces.

The Datadog tracing library, when configured as described here, accepts the spans and traces generated by OpenTelemetry-instrumented code, processes the telemetry, and sends it to Datadog. You can use this approach, for example, if your code has already been instrumented with the OpenTelemetry API, or if you want to instrument using the OpenTelemetry API, and you want to gain the benefits of using the Datadog tracing libraries without changing your code.

If you’re looking for a way to instrument your code with OpenTelemetry and then send span data to Datadog without going through the Datadog tracing library, see OpenTelemetry in Datadog.

要件と制限

  • Datadog Go トレースライブラリ dd-trace-go バージョン 1.5.0 以上。
  • Go バージョン 1.18 以上。
  • Datadog OpenTelemetry API の実装は、アップストリーム OpenTelemetry Go に依存しています。

特記されている通り、以下の OpenTelemetry 機能は、Datadog ライブラリに実装されています。

機能サポートノート
OpenTelemetry コンテキスト伝搬Datadog 分散ヘッダーフォーマットが代わりに使用されます。
スパンプロセッサー非サポート
スパンエクスポーター非サポート
トレース/スパン ID ジェネレーターID の生成は ddtrace が行います。

Datadog トレースプロバイダーを使用するための OpenTelemetry の構成

  1. OpenTelemetry Go Manual Instrumentation ドキュメントに従って、ご希望の手動 OpenTelemetry インスツルメンテーションを Go コードに追加します。

  2. OpenTelemetry パッケージ go.opentelemetry.io/otel を以下のコマンドでインストールします。

    go get go.opentelemetry.io/otel
    
  3. Datadog OpenTelemetry のラッパーパッケージ gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentelemetry を、以下のコマンドでインストールします。

    go get gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentelemetry
    
  4. コードでパッケージをインポートします。

    import (
      "go.opentelemetry.io/otel"
      ddotel "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentelemetry"
    )
    
  5. TracerProvider を作成し、オプションとして Datadog APM 固有のオプションを提供し、トレーサーを停止させる Shutdown メソッドを延期します。

    provider := ddotel.NewTracerProvider()
    defer provider.Shutdown()
    
  6. OpenTelemetry API でトレーサープロバイダーのインスタンスを使用し、グローバルな TracerProvider を設定します。

    otel.SetTracerProvider(provider)
    
  7. アプリケーションを実行します。

Datadog は、これらの OpenTelemetry スパンと他の Datadog APM スパンを組み合わせて、アプリケーションの単一のトレースにします。