Use correct key for tracing hostname field
We now use the `HostNameKey` for the hostname rather than the
`ServiceInstanceIDKey`. We also add the process PID in the same way we
do for conmonrs and update semconv to the latest version.
@@ -2,6 +2,7 @@ package opentelemetry
import (
"context"
+ "fmt"
"os"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
@@ -10,7 +11,7 @@ import (
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
- semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
+ semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
"go.opentelemetry.io/otel/trace"
)
@@ -25,14 +26,15 @@ func Tracer() trace.Tracer {
// InitTracing configures opentelemetry exporter and tracer provider
func InitTracing(ctx context.Context, collectorAddress string, samplingRate int) (*sdktrace.TracerProvider, []otelgrpc.Option, error) {
var tp *sdktrace.TracerProvider
- tracingServiceIDKey, err := os.Hostname()
+ hostname, err := os.Hostname()
if err != nil {
- return nil, nil, err
+ return nil, nil, fmt.Errorf("get hostname: %w", err)
}
res := resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String(tracingServiceName),
- semconv.ServiceInstanceIDKey.String(tracingServiceIDKey),
+ semconv.HostNameKey.String(hostname),
+ semconv.ProcessPIDKey.Int64(int64(os.Getpid())),
)
exporter, err := otlptracegrpc.New(ctx,
otlptracegrpc.WithEndpoint(collectorAddress),
