-
Notifications
You must be signed in to change notification settings - Fork 439
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
contrib/go-redis/redis.v8: add Option to Exclude Raw Command #1026
Changes from all commits
82c7cfd
bd764ae
c5ea938
0c95b43
f624bde
047de40
4754d6b
f18ce83
cba2932
34b7164
f421ca0
0ab271b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,8 +12,9 @@ import ( | |||||
) | ||||||
|
||||||
type clientConfig struct { | ||||||
serviceName string | ||||||
analyticsRate float64 | ||||||
serviceName string | ||||||
analyticsRate float64 | ||||||
excludeRawCommand bool | ||||||
} | ||||||
|
||||||
// ClientOption represents an option that can be used to create or wrap a client. | ||||||
|
@@ -58,3 +59,11 @@ func WithAnalyticsRate(rate float64) ClientOption { | |||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
// WithExcludeRawCommand sets the option to exclude the raw command | ||||||
// for when the command/cache might contain sensitive data | ||||||
func WithExcludeRawCommand(exclude bool) ClientOption { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think this would be better, unless it's bad that we don't have the |
||||||
return func(cfg *clientConfig) { | ||||||
cfg.excludeRawCommand = exclude | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -102,14 +102,18 @@ func (ddh *datadogHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (con | |||||||||||||||||||||||
raw := cmd.String() | ||||||||||||||||||||||||
length := strings.Count(raw, " ") | ||||||||||||||||||||||||
p := ddh.params | ||||||||||||||||||||||||
opts := make([]ddtrace.StartSpanOption, 0, 5+len(ddh.additionalTags)+1) // 5 options below + for additionalTags + for analyticsRate | ||||||||||||||||||||||||
var opts []ddtrace.StartSpanOption | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Generally I'm okay with not pre-allocating the arrays backing a slice unless it has a significant performance impact. I'm not sure if this analysis has been done here, but assuming it was, this change here could be a small performance regression. Have you considered just keeping this line (and the one in |
||||||||||||||||||||||||
opts = append(opts, | ||||||||||||||||||||||||
tracer.SpanType(ext.SpanTypeRedis), | ||||||||||||||||||||||||
tracer.ServiceName(p.config.serviceName), | ||||||||||||||||||||||||
tracer.ResourceName(raw[:strings.IndexByte(raw, ' ')]), | ||||||||||||||||||||||||
tracer.Tag("redis.raw_command", raw), | ||||||||||||||||||||||||
tracer.Tag("redis.args_length", strconv.Itoa(length)), | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if !p.config.excludeRawCommand { | ||||||||||||||||||||||||
opts = append(opts, tracer.Tag("redis.raw_command", raw)) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Comment on lines
+112
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
opts = append(opts, ddh.additionalTags...) | ||||||||||||||||||||||||
if !math.IsNaN(p.config.analyticsRate) { | ||||||||||||||||||||||||
opts = append(opts, tracer.Tag(ext.EventSampleRate, p.config.analyticsRate)) | ||||||||||||||||||||||||
|
@@ -134,16 +138,21 @@ func (ddh *datadogHook) BeforeProcessPipeline(ctx context.Context, cmds []redis. | |||||||||||||||||||||||
raw := commandsToString(cmds) | ||||||||||||||||||||||||
length := strings.Count(raw, " ") | ||||||||||||||||||||||||
p := ddh.params | ||||||||||||||||||||||||
opts := make([]ddtrace.StartSpanOption, 0, 7+len(ddh.additionalTags)+1) // 7 options below + for additionalTags + for analyticsRate | ||||||||||||||||||||||||
var opts []ddtrace.StartSpanOption | ||||||||||||||||||||||||
opts = append(opts, | ||||||||||||||||||||||||
tracer.SpanType(ext.SpanTypeRedis), | ||||||||||||||||||||||||
tracer.ServiceName(p.config.serviceName), | ||||||||||||||||||||||||
tracer.ResourceName(raw[:strings.IndexByte(raw, ' ')]), | ||||||||||||||||||||||||
tracer.Tag("redis.raw_command", raw), | ||||||||||||||||||||||||
tracer.Tag("redis.args_length", strconv.Itoa(length)), | ||||||||||||||||||||||||
tracer.Tag(ext.ResourceName, raw), | ||||||||||||||||||||||||
tracer.Tag("redis.pipeline_length", strconv.Itoa(len(cmds))), | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if !p.config.excludeRawCommand { | ||||||||||||||||||||||||
opts = append(opts, | ||||||||||||||||||||||||
tracer.Tag("redis.raw_command", raw), | ||||||||||||||||||||||||
tracer.Tag(ext.ResourceName, raw)) | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for missing this. The resource name is 100% mandatory for all spans. We can not leave it out. |
||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Comment on lines
+149
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
opts = append(opts, ddh.additionalTags...) | ||||||||||||||||||||||||
if !math.IsNaN(p.config.analyticsRate) { | ||||||||||||||||||||||||
opts = append(opts, tracer.Tag(ext.EventSampleRate, p.config.analyticsRate)) | ||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this part. The Datadog Agent obfuscates this tag and hides all parameters. Why would the fact that it contains sensitive data be an issue?
As for the doc, we should be a bit more specific on what it does.