mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 19:56:44 +00:00
document batch options for open telemetry and clean up comments
This commit is contained in:
parent
0367acc253
commit
a1caed3938
1 changed files with 19 additions and 7 deletions
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/internal/version"
|
"github.com/ethereum/go-ethereum/internal/version"
|
||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
|
|
@ -68,25 +69,36 @@ func Setup(ctx context.Context, endpoint string, sampleRatio float64) (*Telemetr
|
||||||
return nil, fmt.Errorf("failed to create telemetry exporter: %w", err)
|
return nil, fmt.Errorf("failed to create telemetry exporter: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no parent span is available, then sampleRatio of traces are sampled;
|
// Define sampler such that if no parent span is available,
|
||||||
// otherwise, inherit the parent's sampling decision.
|
// then sampleRatio of traces are sampled; otherwise, inherit
|
||||||
|
// the parent's sampling decision.
|
||||||
sampler := sdktrace.ParentBased(sdktrace.TraceIDRatioBased(sampleRatio))
|
sampler := sdktrace.ParentBased(sdktrace.TraceIDRatioBased(sampleRatio))
|
||||||
|
|
||||||
// Create resource with service and client information
|
// Define batch span processor options
|
||||||
|
batchOpts := []sdktrace.BatchSpanProcessorOption{
|
||||||
|
// The maximum number of spans that can be queued before dropping
|
||||||
|
sdktrace.WithMaxQueueSize(sdktrace.DefaultMaxExportBatchSize),
|
||||||
|
// The maximum number of spans to export in a single batch
|
||||||
|
sdktrace.WithMaxExportBatchSize(sdktrace.DefaultMaxExportBatchSize),
|
||||||
|
// How long an export operation can take before timing out
|
||||||
|
sdktrace.WithExportTimeout(sdktrace.DefaultExportTimeout),
|
||||||
|
// How often to export, even if the batch isn't full
|
||||||
|
sdktrace.WithBatchTimeout(5 * time.Second), // SDK default is 5s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define resource with service and client information
|
||||||
res := resource.NewWithAttributes(
|
res := resource.NewWithAttributes(
|
||||||
semconv.SchemaURL,
|
semconv.SchemaURL,
|
||||||
semconv.ServiceName("geth"),
|
semconv.ServiceName("geth"),
|
||||||
attribute.String("client.name", version.ClientName("geth")),
|
attribute.String("client.name", version.ClientName("geth")),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create TracerProvider
|
// Configure TracerProvider and set it as the global tracer provider
|
||||||
tp := sdktrace.NewTracerProvider(
|
tp := sdktrace.NewTracerProvider(
|
||||||
sdktrace.WithSampler(sampler),
|
sdktrace.WithSampler(sampler),
|
||||||
sdktrace.WithBatcher(exporter),
|
sdktrace.WithBatcher(exporter, batchOpts...),
|
||||||
sdktrace.WithResource(res),
|
sdktrace.WithResource(res),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Set as global provider
|
|
||||||
otel.SetTracerProvider(tp)
|
otel.SetTracerProvider(tp)
|
||||||
|
|
||||||
// Set global propagator for context propagation
|
// Set global propagator for context propagation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue