OpenTelemetry Go 應用程式整合
與 OpenTelemetry 整合的主要方法是配置 OpenTelemetry 所監視之任何應用程式的預設 OTLP 匯出程式,以將其資料傳送至 Instana 代理程式。 這在 OpenTelemetry 頁面上說明。
無伺服器 OpenTelemetry Exporter
模組 github.com/instana/go-otel-exporter 提供 OpenTelemetry 匯出器 ,可將 OpenTelemetry 跨距轉換並傳送至 Instana 後端。
Instana Go OpenTelemetry 匯出器主要設計用於在無伺服器環境中使用,例如 AWS Lambda 或 AWS Fargate。 Instana 已透過主機代理程式提供 OpenTelemetry for SaaS 及自行管理解決方案的支援。 不過,如果 Go 應用程式在無伺服器環境中執行 (其中代理程式不存在) ,則無伺服器 OpenTelemetry 匯出器是要執行的方式。
若要使用匯出器,請將模組安裝至專案,使用 instana.New() 建立匯出器的新實例,並將它新增至「追蹤器提供者」。
匯出器預期必須提供兩個 Instana 環境變數 給應用程式:
INSTANA_AGENT_KEYINSTANA_ENDPOINT_URL
匯出器的完整用法範例說明如下:
package main
import (
"context"
"time"
instana "github.com/instana/go-otel-exporter"
"go.opentelemetry.io/otel"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
)
// This example application demonstrates how to use the Instana OTel Exporter.
// Make sure to provide the required environment variables before run the application:
// * INSTANA_ENDPOINT_URL
// * INSTANA_AGENT_KEY
func main() {
ch := make(chan bool)
// Acquire an instance of the Instana OTel Exporter
exporter := instana.New()
// Setup and bootstrap the tracer provider
tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
)
otel.SetTracerProvider(tracerProvider)
ctx := context.Background()
// Instrument something with OTel
tracer := otel.Tracer("my-traced-tech")
_, span := tracer.Start(ctx, "my_span", trace.WithSpanKind(trace.SpanKindServer))
// This simulates the time that a span takes to be completed
time.Sleep(time.Millisecond * 400)
span.End()
<-ch
}
當 OpenTelemetry 所監視的應用程式執行時, Instana 匯出程式會將 OpenTelemetry 跨距轉換為 Instana 跨距,並將它們傳送至後端端點。
OpenTelemetry 追蹤視覺化將呈現在 Instana 使用者介面中,就像一般 Instana 追蹤跨距一樣。