Skip to content

Support valkey-go tracing #3081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6aa8d69
Support valkey-go tracing
keisku Jan 12, 2025
fe59e6d
as per DD_APM_PEER_TAGS_AGGREGATION in agent
keisku Jan 16, 2025
26c6621
Merge branch 'main' into keisku/valkey-go-support
darccio Jan 17, 2025
9479b69
Merge remote-tracking branch 'origin' into keisku/valkey-go-support
keisku Jan 18, 2025
49ebeed
update example as per best practice
keisku Jan 18, 2025
90f6c43
fix doc
keisku Jan 18, 2025
46cacc3
fix spanName
keisku Jan 18, 2025
6d5b6f6
update contribIntegrations
keisku Jan 18, 2025
e99f4d7
rename to github.com/valkey-io/valkey-go
keisku Jan 21, 2025
4031cd7
remove App Analytics which was deprecated
keisku Jan 21, 2025
aae0a85
for consistency with the other examples
keisku Jan 21, 2025
14b4d21
remove ValkeyClientCommand* tags
keisku Jan 21, 2025
6197ac1
there is not concept of db.instance in valkey / redis
keisku Jan 21, 2025
7b7329f
remove db.type:valkey
keisku Jan 21, 2025
fca4a18
remove db.application
keisku Jan 21, 2025
e7758a3
fix valkey.raw_command behavior
keisku Jan 21, 2025
cdb4129
add db.out tag
keisku Jan 21, 2025
21434c3
typo
keisku Jan 21, 2025
27b0fec
remove valkeyotel tags
keisku Jan 23, 2025
06360d2
rename to out.db (ext.TargetDB)
keisku Jan 23, 2025
b8c5c35
remove peer.* tags
keisku Jan 23, 2025
fba84df
rework DD_TRACE_VALKEY_RAW_COMMAND behavior
keisku Jan 23, 2025
25088d1
fix error handling when a span finishes
keisku Jan 23, 2025
d9bb011
fix raw command + add missing service name option + refactor
rarguelloF Jan 27, 2025
4ab8179
Merge branch 'main' into keisku/valkey-go-support
rarguelloF Jan 27, 2025
7eeeb6c
fix: go mod tidy smoke test
keisku Jan 28, 2025
b9e6353
Merge branch 'main' into keisku/valkey-go-support
rarguelloF Jan 28, 2025
7c87d09
Merge branch 'main' into keisku/valkey-go-support
rarguelloF Jan 28, 2025
3234dc9
fix github workflows file
rarguelloF Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/unit-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ jobs:
image: redis:3.2
ports:
- 6379:6379
valkey:
image: valkey/valkey:8
ports:
- "6380:6380"
# https://valkey.io/topics/acl/
command: [ "valkey-server", "--port", "6380", "--requirepass", "password-for-default" ]
elasticsearch2:
image: elasticsearch:2
env:
Expand Down
40 changes: 40 additions & 0 deletions contrib/valkey-go/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016 Datadog, Inc.

package valkey_test

import (
"context"
"log/slog"

"github.com/valkey-io/valkey-go"
valkeytrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/valkey-go"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

// To start tracing Valkey, simply create a new client using the library and continue
// using as you normally would.
func Example() {
vk, err := valkeytrace.NewClient(valkey.ClientOption{
InitAddress: []string{"localhost:6379"},
})
if err != nil {
slog.Error(err.Error())
return
}

span, ctx := tracer.StartSpanFromContext(context.Background(), "parent.request",
tracer.SpanType(ext.SpanTypeValkey),
tracer.ServiceName("web"),
tracer.ResourceName("/home"),
)

if err := vk.Do(ctx, vk.B().Set().Key("key").Value("value").Build()).Error(); err != nil {
slog.ErrorContext(ctx, "set a value", slog.Any("error", err))
}

span.Finish()
}
66 changes: 66 additions & 0 deletions contrib/valkey-go/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016 Datadog, Inc.

// Package redis provides tracing functions for tracing the go-redis/redis package (https://github.com/go-redis/redis).
// This package supports versions up to go-redis 6.15.
package valkey

import (
"math"

"gopkg.in/DataDog/dd-trace-go.v1/internal"
"gopkg.in/DataDog/dd-trace-go.v1/internal/namingschema"
)

type clientConfig struct {
spanName string
analyticsRate float64
skipRaw bool
}

// ClientOption represents an option that can be used to create or wrap a client.
type ClientOption func(*clientConfig)

func defaults(cfg *clientConfig) {
cfg.spanName = namingschema.OpName(namingschema.ValkeyOutbound)
if internal.BoolEnv("DD_TRACE_VALKEY_ANALYTICS_ENABLED", false) {
cfg.analyticsRate = 1.0
} else {
cfg.analyticsRate = math.NaN()
}
cfg.skipRaw = internal.BoolEnv("DD_TRACE_VALKEY_SKIP_RAW_COMMAND", false)
}

// WithSkipRawCommand reports whether to skip setting the raw command value
// on instrumenation spans. This may be useful if the Datadog Agent is not
// set up to obfuscate this value and it could contain sensitive information.
func WithSkipRawCommand(skip bool) ClientOption {
return func(cfg *clientConfig) {
cfg.skipRaw = skip
}
}

// WithAnalytics enables Trace Analytics for all started spans.
func WithAnalytics(on bool) ClientOption {
return func(cfg *clientConfig) {
if on {
cfg.analyticsRate = 1.0
} else {
cfg.analyticsRate = math.NaN()
}
}
}

// WithAnalyticsRate sets the sampling rate for Trace Analytics events
// correlated to started spans.
func WithAnalyticsRate(rate float64) ClientOption {
return func(cfg *clientConfig) {
if rate >= 0.0 && rate <= 1.0 {
cfg.analyticsRate = rate
} else {
cfg.analyticsRate = math.NaN()
}
}
}
Loading
Loading