Documentation
¶
Index ¶
- Constants
- Variables
- func AddResources(attrs ...attribute.KeyValue)
- func Extract(ctx context.Context, p propagation.TextMapPropagator, metadata *metadata.MD) (baggage.Baggage, sdktrace.SpanContext)
- func Inject(ctx context.Context, p propagation.TextMapPropagator, metadata *metadata.MD)
- func ParseFullMethod(fullMethod string) (string, []attribute.KeyValue)
- func PeerAttr(addr string) []attribute.KeyValue
- func PeerFromCtx(ctx context.Context) string
- func SpanInfo(fullMethod, peerAddress string) (string, []attribute.KeyValue)
- func StartAgent(c Config)
- func StatusCodeAttr(c gcodes.Code) attribute.KeyValue
- func StopAgent()
- func TracerFromContext(ctx context.Context) (tracer trace.Tracer)
- type Config
Constants ¶
const ( // GRPCStatusCodeKey is convention for numeric status code of a gRPC request. GRPCStatusCodeKey = attribute.Key("rpc.grpc.status_code") // RPCNameKey is the name of message transmitted or received. RPCNameKey = attribute.Key("name") // RPCMessageTypeKey is the type of message transmitted or received. RPCMessageTypeKey = attribute.Key("message.type") // RPCMessageIDKey is the identifier of message transmitted or received. RPCMessageIDKey = attribute.Key("message.id") // RPCMessageCompressedSizeKey is the compressed size of the message transmitted or received in bytes. RPCMessageCompressedSizeKey = attribute.Key("message.compressed_size") // RPCMessageUncompressedSizeKey is the uncompressed size of the message // transmitted or received in bytes. RPCMessageUncompressedSizeKey = attribute.Key("message.uncompressed_size") )
const TraceName = "go-zero"
TraceName represents the tracing name.
Variables ¶
var ( // RPCSystemGRPC is the semantic convention for gRPC as the remoting system. RPCSystemGRPC = semconv.RPCSystemKey.String("grpc") // RPCNameMessage is the semantic convention for a message named message. RPCNameMessage = RPCNameKey.String("message") // RPCMessageTypeSent is the semantic conventions for sent RPC message types. RPCMessageTypeSent = RPCMessageTypeKey.String("SENT") // RPCMessageTypeReceived is the semantic conventions for the received RPC message types. RPCMessageTypeReceived = RPCMessageTypeKey.String("RECEIVED") )
Semantic conventions for common RPC attributes.
var ( // MessageSent is the type of sent messages. MessageSent = messageType(RPCMessageTypeSent) // MessageReceived is the type of received messages. MessageReceived = messageType(RPCMessageTypeReceived) )
var ( // SpanIDFromContext returns the span id from ctx. SpanIDFromContext = ztrace.SpanIDFromContext // TraceIDFromContext returns the trace id from ctx. TraceIDFromContext = ztrace.TraceIDFromContext )
var TraceIdKey = http.CanonicalHeaderKey("x-trace-id")
TraceIdKey is the trace id header. https://www.w3.org/TR/trace-context/#trace-id May change it to trace-id afterward.
Functions ¶
func AddResources ¶ added in v1.6.0
AddResources add more resources in addition to configured trace name.
func Extract ¶
func Extract(ctx context.Context, p propagation.TextMapPropagator, metadata *metadata.MD) ( baggage.Baggage, sdktrace.SpanContext)
Extract extracts the metadata from ctx.
func Inject ¶
func Inject(ctx context.Context, p propagation.TextMapPropagator, metadata *metadata.MD)
Inject injects cross-cutting concerns from the ctx into the metadata.
func ParseFullMethod ¶
ParseFullMethod returns the method name and attributes.
func PeerFromCtx ¶
PeerFromCtx returns the peer from ctx.
func StartAgent ¶
func StartAgent(c Config)
StartAgent starts an opentelemetry agent. It uses sync.Once to ensure the agent is initialized only once, similar to prometheus.StartAgent and logx.SetUp. This prevents multiple ServiceConf.SetUp() calls from reinitializing the global tracer provider when running multiple servers (e.g., REST + RPC) in the same process.
func StatusCodeAttr ¶
StatusCodeAttr returns an attribute.KeyValue that represents the give c.
Types ¶
type Config ¶
type Config struct {
Name string `json:",optional"`
Endpoint string `json:",optional"`
Sampler float64 `json:",default=1.0"`
Batcher string `json:",default=jaeger,options=jaeger|zipkin|otlpgrpc|otlphttp|file"`
// OtlpHeaders represents the headers for OTLP gRPC or HTTP transport.
// For example:
// uptrace-dsn: 'http://project2_secret_token@localhost:14317/2'
OtlpHeaders map[string]string `json:",optional"`
// OtlpHttpPath represents the path for OTLP HTTP transport.
// For example
// /v1/traces
OtlpHttpPath string `json:",optional"`
// OtlpHttpSecure represents the scheme to use for OTLP HTTP transport.
OtlpHttpSecure bool `json:",optional"`
// Disabled indicates whether StartAgent starts the agent.
Disabled bool `json:",optional"`
}
A Config is an opentelemetry config.