Data Type | SDK Module | Exporter |
Log | go.opentelemetry.io/otel/sdk/log | otlploghttp |
Trace | go.opentelemetry.io/otel/sdk/trace | otlptracehttp |
Metric | go.opentelemetry.io/otel/sdk/metric | otlpmetrichttp |
topic_id for each topic. For detailed operations, see Create Log Topic.Network type | Domain Name Format | Scenario |
Public Network | <region>.cls.tencentcs.com | Local debugging, non-Tencent Cloud environments, cross-cloud reporting |
Private Network | <region>.cls.tencentyun.com | Deployed in Tencent Cloud VPCs/CVMs within the same region, with no public network traffic fees and low latency. |
Region | Public Endpoint | Private Endpoint |
Guangzhou | ap-guangzhou.cls.tencentcs.com | ap-guangzhou.cls.tencentyun.com |
Shanghai | ap-shanghai.cls.tencentcs.com | ap-shanghai.cls.tencentyun.com |
Beijing | ap-beijing.cls.tencentcs.com | ap-beijing.cls.tencentyun.com |
Singapore | ap-singapore.cls.tencentcs.com | ap-singapore.cls.tencentyun.com |
# OpenTelemetry Corego get go.opentelemetry.io/otelgo get go.opentelemetry.io/otel/sdk# Loggo get go.opentelemetry.io/otel/loggo get go.opentelemetry.io/otel/sdk/loggo get go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp# Tracego get go.opentelemetry.io/otel/sdk/tracego get go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp# Metricgo get go.opentelemetry.io/otel/sdk/metricgo get go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp# Semantic Conventionsgo get go.opentelemetry.io/otel/semconv/v1.37.0
Authorization: Basic base64(SecretId:SecretKey)topic_id: <Your topic_id>
import "encoding/base64"func basicAuth(username, password string) string {auth := username + ":" + passwordreturn base64.StdEncoding.EncodeToString([]byte(auth))}
package mainimport ("context""go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp")func otlplog() {ctx := context.Background()// Create an OTLP/HTTP Log Exporterexporter, err := otlploghttp.New(ctx,otlploghttp.WithEndpoint("ap-guangzhou.cls.tencentcs.com"),otlploghttp.WithHeaders(map[string]string{"Authorization": "Basic " + basicAuth("<SecretId>", "<SecretKey>"),"topic_id": "<log topic_id>",}),)if err != nil {panic(err)}_ = exporter// Subsequently, you can upload logs by using sdklog.NewLoggerProvider(...) to attach the exporter to the LoggerProvider.}
Parameter | Description |
Endpoint | The CLS OTLP endpoint domain name. Do not include the http:// prefix. |
Authorization | The authentication header in the Basic base64(AK:SK) format |
topic_id | The CLS log topic ID corresponding to the log data |
sdklog.WithProcessor(sdklog.NewBatchProcessor(exporter,sdklog.WithExportInterval(5*time.Second),sdklog.WithExportMaxBatchSize(512),))
package mainimport ("context""log""go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp")func otlptrace() {ctx := context.Background()// Create an OTLP/HTTP Trace ExportertraceExporter, err := otlptracehttp.New(ctx,otlptracehttp.WithEndpoint("ap-guangzhou.cls.tencentcs.com"),otlptracehttp.WithHeaders(map[string]string{"Authorization": "Basic " + basicAuth("<SecretId>", "<SecretKey>"),"topic_id": "<trace topic_id>",}),)if err != nil {log.Printf("create trace exporter failed: %v", err)return}_ = traceExporter// Subsequently, you can upload traces by using sdktrace.NewTracerProvider(...) to attach the exporter.}
Sampler | Description |
AlwaysSample() | Samples all traffic, suitable for testing or low-traffic services. |
NeverSample() | Samples no traffic. |
TraceIDRatioBased(0.1) | Samples traffic at a ratio (10%), recommended for production. |
ParentBased(...) | Decides based on the parent Span, suitable for distributed tracing scenarios. |
sdktrace.WithSpanProcessor(sdktrace.NewBatchSpanProcessor(traceExporter,sdktrace.WithMaxExportBatchSize(512),sdktrace.WithBatchTimeout(5*time.Second),))
package mainimport ("context""go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp")func otlpMetric() {ctx := context.Background()// Create an OTLP/HTTP Metric Exporterexporter, err := otlpmetrichttp.New(ctx,otlpmetrichttp.WithEndpoint("ap-guangzhou.cls.tencentcs.com"),otlpmetrichttp.WithHeaders(map[string]string{"Authorization": "Basic " + basicAuth("<SecretId>", "<SecretKey>"),"topic_id": "<metric topic_id>",}),)if err != nil {panic(err)}_ = exporter// Subsequently, you can periodically upload metrics by attaching the exporter via metric.NewMeterProvider(metric.WithReader(metric.NewPeriodicReader(exporter, ...))).}
Type | API | Scenario |
Counter | Int64Counter / Float64Counter | Monotonically increasing, such as total number of requests |
UpDownCounter | Int64UpDownCounter | Can increase or decrease, such as number of connections |
Histogram | Float64Histogram | Distribution statistics, such as latency |
Gauge (Observer) | Float64ObservableGauge | Instantaneous value, such as CPU utilization |
metric.NewPeriodicReader(exporter,metric.WithInterval(15*time.Second), // Recommended interval for production: 15~30 secondsmetric.WithTimeout(5*time.Second),)
res, _ := resource.New(ctx,resource.WithFromEnv(),resource.WithProcess(),resource.WithTelemetrySDK(),resource.WithHost(),resource.WithAttributes(semconv.ServiceNameKey.String("my-service"),semconv.ServiceNamespaceKey.String("Production"),semconv.ServiceVersionKey.String("v1.0.0"),semconv.DeploymentEnvironmentKey.String("prod"),),)
Field | Description |
service.name | Service name, required |
service.namespace | Service namespace (such as environment name) |
service.version | Service Version |
cls:PushLog).Basic <base64(AK:SK)>.topic_id and the Endpoint are in different regions. Ensure that the region of the topic matches the region of the Endpoint.Shutdown.WithEndpoint, provide only the domain name. Do not include http:// or https://.WithInsecure() option.<region>.cls.tencentyun.com): It is recommended for deployments within Tencent Cloud VPCs or CVMs in the same region, as it incurs no public network traffic fees and offers lower latency.<region>.cls.tencentcs.com): Use this for local debugging, non-Tencent Cloud environments, or cross-cloud provider environments.topic_id. Otherwise, a "topic not found" error will be reported."x-cross-region": "ap-guangzhou"
Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan