mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 19:30:44 +00:00
all: add ability to set arbitrary tags on resource struct
This commit is contained in:
parent
a51692908b
commit
ac01565566
4 changed files with 24 additions and 3 deletions
|
|
@ -201,6 +201,7 @@ var (
|
||||||
utils.RPCTelemetryUserFlag,
|
utils.RPCTelemetryUserFlag,
|
||||||
utils.RPCTelemetryPasswordFlag,
|
utils.RPCTelemetryPasswordFlag,
|
||||||
utils.RPCTelemetryInstanceIDFlag,
|
utils.RPCTelemetryInstanceIDFlag,
|
||||||
|
utils.RPCTelemetryTagsFlag,
|
||||||
utils.RPCTelemetrySampleRatioFlag,
|
utils.RPCTelemetrySampleRatioFlag,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1074,6 +1074,12 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
|
||||||
Category: flags.APICategory,
|
Category: flags.APICategory,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RPCTelemetryTagsFlag = &cli.StringFlag{
|
||||||
|
Name: "rpc.telemetry.tags",
|
||||||
|
Usage: "Comma-separated tags (key/values) added as attributes to the OpenTelemetry resource struct",
|
||||||
|
Category: flags.APICategory,
|
||||||
|
}
|
||||||
|
|
||||||
RPCTelemetrySampleRatioFlag = &cli.Float64Flag{
|
RPCTelemetrySampleRatioFlag = &cli.Float64Flag{
|
||||||
Name: "rpc.telemetry.sample-ratio",
|
Name: "rpc.telemetry.sample-ratio",
|
||||||
Usage: "Defines the sampling ratio for RPC telemetry (0.0 to 1.0)",
|
Usage: "Defines the sampling ratio for RPC telemetry (0.0 to 1.0)",
|
||||||
|
|
@ -1543,7 +1549,6 @@ func setOpenTelemetry(ctx *cli.Context, cfg *node.Config) {
|
||||||
if ctx.IsSet(RPCTelemetryFlag.Name) {
|
if ctx.IsSet(RPCTelemetryFlag.Name) {
|
||||||
tcfg.Enabled = ctx.Bool(RPCTelemetryFlag.Name)
|
tcfg.Enabled = ctx.Bool(RPCTelemetryFlag.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.IsSet(RPCTelemetryEndpointFlag.Name) {
|
if ctx.IsSet(RPCTelemetryEndpointFlag.Name) {
|
||||||
tcfg.Endpoint = ctx.String(RPCTelemetryEndpointFlag.Name)
|
tcfg.Endpoint = ctx.String(RPCTelemetryEndpointFlag.Name)
|
||||||
}
|
}
|
||||||
|
|
@ -1553,10 +1558,13 @@ func setOpenTelemetry(ctx *cli.Context, cfg *node.Config) {
|
||||||
if ctx.IsSet(RPCTelemetryPasswordFlag.Name) {
|
if ctx.IsSet(RPCTelemetryPasswordFlag.Name) {
|
||||||
tcfg.AuthPassword = ctx.String(RPCTelemetryPasswordFlag.Name)
|
tcfg.AuthPassword = ctx.String(RPCTelemetryPasswordFlag.Name)
|
||||||
}
|
}
|
||||||
tcfg.SampleRatio = ctx.Float64(RPCTelemetrySampleRatioFlag.Name)
|
|
||||||
if ctx.IsSet(RPCTelemetryInstanceIDFlag.Name) {
|
if ctx.IsSet(RPCTelemetryInstanceIDFlag.Name) {
|
||||||
tcfg.InstanceID = ctx.String(RPCTelemetryInstanceIDFlag.Name)
|
tcfg.InstanceID = ctx.String(RPCTelemetryInstanceIDFlag.Name)
|
||||||
}
|
}
|
||||||
|
if ctx.IsSet(RPCTelemetryTagsFlag.Name) {
|
||||||
|
tcfg.Tags = ctx.String(RPCTelemetryTagsFlag.Name)
|
||||||
|
}
|
||||||
|
tcfg.SampleRatio = ctx.Float64(RPCTelemetrySampleRatioFlag.Name)
|
||||||
|
|
||||||
if tcfg.Endpoint != "" && !tcfg.Enabled {
|
if tcfg.Endpoint != "" && !tcfg.Enabled {
|
||||||
log.Warn(fmt.Sprintf("OpenTelemetry endpoint configured but telemetry is not enabled, use --%s to enable.", RPCTelemetryFlag.Name))
|
log.Warn(fmt.Sprintf("OpenTelemetry endpoint configured but telemetry is not enabled, use --%s to enable.", RPCTelemetryFlag.Name))
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/internal/version"
|
"github.com/ethereum/go-ethereum/internal/version"
|
||||||
|
|
@ -121,14 +122,24 @@ func SetupTelemetry(cfg node.OpenTelemetryConfig, stack *node.Node) error {
|
||||||
sdktrace.WithBatchTimeout(time.Duration(sdktrace.DefaultScheduleDelay) * time.Millisecond),
|
sdktrace.WithBatchTimeout(time.Duration(sdktrace.DefaultScheduleDelay) * time.Millisecond),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define resource with service and client information
|
// Define resource attributes
|
||||||
var attr = []attribute.KeyValue{
|
var attr = []attribute.KeyValue{
|
||||||
semconv.ServiceName("geth"),
|
semconv.ServiceName("geth"),
|
||||||
attribute.String("client.name", version.ClientName("geth")),
|
attribute.String("client.name", version.ClientName("geth")),
|
||||||
}
|
}
|
||||||
|
// Add instance ID if provided
|
||||||
if cfg.InstanceID != "" {
|
if cfg.InstanceID != "" {
|
||||||
attr = append(attr, semconv.ServiceInstanceID(cfg.InstanceID))
|
attr = append(attr, semconv.ServiceInstanceID(cfg.InstanceID))
|
||||||
}
|
}
|
||||||
|
// Add custom tags if provided
|
||||||
|
if cfg.Tags != "" {
|
||||||
|
for tag := range strings.SplitSeq(cfg.Tags, ",") {
|
||||||
|
key, value, ok := strings.Cut(tag, "=")
|
||||||
|
if ok {
|
||||||
|
attr = append(attr, attribute.String(key, value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
res := resource.NewWithAttributes(semconv.SchemaURL, attr...)
|
res := resource.NewWithAttributes(semconv.SchemaURL, attr...)
|
||||||
|
|
||||||
// Configure TracerProvider and set it as the global tracer provider
|
// Configure TracerProvider and set it as the global tracer provider
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,7 @@ type Config struct {
|
||||||
type OpenTelemetryConfig struct {
|
type OpenTelemetryConfig struct {
|
||||||
Enabled bool `toml:",omitempty"`
|
Enabled bool `toml:",omitempty"`
|
||||||
|
|
||||||
|
Tags string `toml:",omitempty"`
|
||||||
InstanceID string `toml:",omitempty"`
|
InstanceID string `toml:",omitempty"`
|
||||||
|
|
||||||
// Exporter endpoint.
|
// Exporter endpoint.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue