https://signoz.io logo
#support
Title
# support
h

Hardik Agrawal

02/28/2022, 11:04 AM
Hi I have auto instrumented my grpc go lang application by adding interceptors as done here : https://github.com/open-telemetry/opentelemetry-go/blob/example/grpc/v0.10.0/example/grpc/server/main.go I also used this third party library to instrument by database metrics : https://github.com/signalfx/splunk-otel-go/tree/main/instrumentation/github.com/jinzhu/gorm/splunkgorm However for a single request I am seeing two traces created.. one for application and for database. Is there a way to have the same trace id associated with both app and database to get a unified view?
I have used the same trace provider in both app and db.
Copy code
db, err = splunkgorm.Open(PostgresDriver, connString,
			splunksql.WithAttributes([]attribute.KeyValue{
				semconv.DBSystemCockroachdb,
				semconv.DBNameKey.String("test"),
			}),
			splunksql.WithTracerProvider(<passed from app>),
		)
Copy code
func getTraceProvider(svcName string, server string) (*sdkTrace.TracerProvider, error) {
	res, err := sdkResource.Merge(sdkResource.NewWithAttributes(
		semconv.SchemaURL,
		semconv.ServiceNameKey.String(svcName),
		semconv.ServiceNamespaceKey.String(server),
	), sdkResource.Default())
	if err != nil {
		panic(err)
	}

	provider := sdkTrace.NewTracerProvider(
		sdkTrace.WithResource(res),
	)
	otel.SetTracerProvider(provider)
	otel.SetTextMapPropagator(propagation.TraceContext{})
	return provider, nil
}

func configureOtlp(ctx context.Context, server, svcName string) (*sdkTrace.TracerProvider, func()) {
	provider, err := getTraceProvider(svcName, server)

	exp, err := otlptrace.New(
		context.Background(),
		otlptracegrpc.NewClient(
			otlptracegrpc.WithInsecure(),
			otlptracegrpc.WithEndpoint("localhost:4317"),
		),
	)
	if err != nil {
		panic(err)
	}

	bsp := sdkTrace.NewBatchSpanProcessor(exp)
	provider.RegisterSpanProcessor(bsp)

	return provider, func() {
		if err := provider.Shutdown(ctx); err != nil {
			panic(err)
		}
	}
}
p

Pranay

02/28/2022, 11:07 AM
@User do you have insights on this?
v

Vishal Sharma

02/28/2022, 12:00 PM
Are you passing active span details as part of context? @User We don’t have any sample grpc app but from my experience we should pass active span details in context. For example in this module it’s clearly written that we have to pass active span details to ctx variable: https://github.com/uptrace/opentelemetry-go-extra/tree/main/otelgorm
🙌 1
h

Hardik Agrawal

02/28/2022, 12:02 PM
I just checked, we are using gorm v1 which does not support passing context, we will have to upgrade to gorm v2 to do this. Will try out with the update. Thanks!
👍 1
v

Vishal Sharma

02/28/2022, 12:04 PM
Also any specific reason why you went for splunk otel for gorm tracing rather than otelgorm?
h

Hardik Agrawal

02/28/2022, 12:10 PM
We use https://v1.gorm.io/ hence I tried using splunk. Had instrumented with otelgorm as well but got the same results so thought this could be the issue.
👌 1
5 Views