dd-trace-go icon indicating copy to clipboard operation
dd-trace-go copied to clipboard

contrib/go-redis/redis: With env and version

Open xrn opened this issue 2 years ago • 3 comments

Following: https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=logs

In redis tracer we can find

// WithServiceName sets the given service name for the client.
func WithServiceName(name string) ClientOption {
	return func(cfg *clientConfig) {
		cfg.serviceName = name
	}
}

But there is no option to set env and version which is required in my case

xrn avatar Dec 21 '21 11:12 xrn

Environment and version are specific to the running application. You set these when starting the tracer using tracer.WithEnv and tracer.WithService. The Redis client will inherit these, which is correct given that client is part of the original application.

gbbr avatar Jan 04 '22 11:01 gbbr

@gbbr I am trying to use it with my lambda but have there no tracer itself

import (
	"context"
	"encoding/json"
	"errors"

	ddlambda "github.com/DataDog/datadog-lambda-go"
	golambda "github.com/aws/aws-lambda-go/lambda"
)

func (d *deps) lambdaHandler(ctx context.Context) error {
...

type deps struct {
	ElastiCache      redis.UniversalClient
}

func main() {
	d := deps{
		ElastiCache: redistrace.NewClient(
			&redis.Options{
				Addr: os.Getenv("elastiCacheUrl"),
			},
			redistrace.WithServiceName("ElastiCache"),
			redistrace.WithAnalytics(true),
		),
	}

       config = &ddlambda.Config{
		DDTraceEnabled:        true,
		MergeXrayTraces:       true,
		ShouldUseLogForwarder: true,
	}

        golambda.Start(ddlambda.WrapHandler(d.lambdaHandler, config))
}

Any Idea how to add env and version to redistracer?

xrn avatar Jan 05 '22 08:01 xrn

I see. This repository is dd-trace-go. Can you please close this issue and open it in datadog-lambda-go? They should likely add the ability for you to set service, env, and version when starting (ddlambda.WrapHandler). However, this is just an assumed solution since I am not familiar with that project. Perhaps they should be made part of ddlambda.Config.

gbbr avatar Jan 05 '22 12:01 gbbr

Closed due to resolution in other issue but feel free to create a new issue in the future if the problem persists or reach out to support

zarirhamza avatar Mar 08 '23 17:03 zarirhamza