Skip to content

Commit

Permalink
Merge branch 'main' into hannahkm/add-codeowners
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahkm authored Jan 28, 2025
2 parents be9e080 + f0ed584 commit 5095868
Show file tree
Hide file tree
Showing 24 changed files with 749 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/service-extensions-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Publish Service Extensions Callout images packages
on:
push:
tags:
- 'v*.*'
- 'v[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
inputs:
tag_name:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/system-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ jobs:
weblog-variant: graphql-go
- scenario: GRAPHQL_APPSEC
weblog-variant: gqlgen
# Service Extensions System Tests
- scenario: EXTERNAL_PROCESSING
- scenario: EXTERNAL_PROCESSING_BLOCKING

fail-fast: false
env:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/unit-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ jobs:
image: redis:3.2
ports:
- 6379:6379
valkey:
image: valkey/valkey:8
env:
VALKEY_EXTRA_FLAGS: "--port 6380 --requirepass password-for-default"
ports:
- 6380:6380
elasticsearch2:
image: elasticsearch:2
env:
Expand Down
4 changes: 2 additions & 2 deletions contrib/go-redis/redis.v7/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func additionalTagOptions(client redis.UniversalClient) []ddtrace.StartSpanOptio
opt := clientOptions.Options()
if opt.Addr == "FailoverClient" {
additionalTags = []ddtrace.StartSpanOption{
tracer.Tag("out.db", strconv.Itoa(opt.DB)),
tracer.Tag(ext.TargetDB, strconv.Itoa(opt.DB)),
tracer.Tag(ext.RedisDatabaseIndex, opt.DB),
}
} else {
Expand All @@ -91,7 +91,7 @@ func additionalTagOptions(client redis.UniversalClient) []ddtrace.StartSpanOptio
additionalTags = []ddtrace.StartSpanOption{
tracer.Tag(ext.TargetHost, host),
tracer.Tag(ext.TargetPort, port),
tracer.Tag("out.db", strconv.Itoa(opt.DB)),
tracer.Tag(ext.TargetDB, strconv.Itoa(opt.DB)),
tracer.Tag(ext.RedisDatabaseIndex, opt.DB),
}
}
Expand Down
4 changes: 2 additions & 2 deletions contrib/go-redis/redis.v8/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func additionalTagOptions(client redis.UniversalClient) []ddtrace.StartSpanOptio
opt := clientOptions.Options()
if opt.Addr == "FailoverClient" {
additionalTags = []ddtrace.StartSpanOption{
tracer.Tag("out.db", strconv.Itoa(opt.DB)),
tracer.Tag(ext.TargetDB, strconv.Itoa(opt.DB)),
tracer.Tag(ext.RedisDatabaseIndex, opt.DB),
}
} else {
Expand All @@ -90,7 +90,7 @@ func additionalTagOptions(client redis.UniversalClient) []ddtrace.StartSpanOptio
additionalTags = []ddtrace.StartSpanOption{
tracer.Tag(ext.TargetHost, host),
tracer.Tag(ext.TargetPort, port),
tracer.Tag("out.db", strconv.Itoa(opt.DB)),
tracer.Tag(ext.TargetDB, strconv.Itoa(opt.DB)),
tracer.Tag(ext.RedisDatabaseIndex, opt.DB),
}
}
Expand Down
4 changes: 2 additions & 2 deletions contrib/go-redis/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (c *Pipeliner) execWithContext(ctx context.Context) ([]redis.Cmder, error)
tracer.ResourceName("redis"),
tracer.Tag(ext.TargetHost, p.host),
tracer.Tag(ext.TargetPort, p.port),
tracer.Tag("out.db", strconv.Itoa(p.db)),
tracer.Tag(ext.TargetDB, strconv.Itoa(p.db)),
tracer.Tag(ext.Component, componentName),
tracer.Tag(ext.SpanKind, ext.SpanKindClient),
tracer.Tag(ext.DBSystem, ext.DBSystemRedis),
Expand Down Expand Up @@ -202,7 +202,7 @@ func createWrapperFromClient(tc *Client) func(oldProcess func(cmd redis.Cmder) e
tracer.ResourceName(parts[0]),
tracer.Tag(ext.TargetHost, p.host),
tracer.Tag(ext.TargetPort, p.port),
tracer.Tag("out.db", strconv.Itoa(p.db)),
tracer.Tag(ext.TargetDB, strconv.Itoa(p.db)),
tracer.Tag("redis.raw_command", raw),
tracer.Tag("redis.args_length", strconv.Itoa(length)),
tracer.Tag(ext.Component, componentName),
Expand Down
13 changes: 13 additions & 0 deletions contrib/internal/httptrace/httptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"context"
"fmt"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
"gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry"
"net/http"
"strconv"
"strings"
"sync"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
Expand All @@ -27,6 +29,8 @@ var (
cfg = newConfig()
)

var reportTelemetryConfigOnce sync.Once

type inferredSpanCreatedCtxKey struct{}

type FinishSpanFunc = func(status int, errorFn func(int) bool, opts ...tracer.FinishOption)
Expand All @@ -37,6 +41,15 @@ func StartRequestSpan(r *http.Request, opts ...ddtrace.StartSpanOption) (tracer.
// Append our span options before the given ones so that the caller can "overwrite" them.
// TODO(): rework span start option handling (https://github.com/DataDog/dd-trace-go/issues/1352)

// we cannot track the configuration in newConfig because it's called during init() and the the telemetry client
// is not initialized yet
reportTelemetryConfigOnce.Do(func() {
telemetry.GlobalClient.ConfigChange([]telemetry.Configuration{
{Name: "inferred_proxy_services_enabled", Value: cfg.inferredProxyServicesEnabled},
})
log.Debug("internal/httptrace: telemetry.ConfigChange called with cfg: %v:", cfg)
})

var ipTags map[string]string
if cfg.traceClientIP {
ipTags, _ = httpsec.ClientIPTags(r.Header, true, r.RemoteAddr)
Expand Down
6 changes: 4 additions & 2 deletions contrib/internal/telemetrytest/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -87,8 +88,9 @@ func TestTelemetryEnabled(t *testing.T) {
if strings.Contains(pkg.ImportPath, "/test") || strings.Contains(pkg.ImportPath, "/internal") || strings.Contains(pkg.ImportPath, "/cmd") {
continue
}
p := strings.Replace(pkg.Dir, pkg.Root, "../..", 1)
if strings.Contains(p, "/contrib/net/http/client") || strings.Contains(p, "/contrib/os") {
sep := string(os.PathSeparator)
p := strings.Replace(pkg.Dir, pkg.Root, filepath.Join("..", ".."), 1)
if strings.Contains(p, filepath.Join(sep, "contrib", "net", "http", "client")) || strings.Contains(p, filepath.Join(sep, "contrib", "os")) {
continue
}
if !pkg.hasTelemetryImport(t) {
Expand Down
4 changes: 2 additions & 2 deletions contrib/redis/go-redis.v9/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func additionalTagOptions(client redis.UniversalClient) []ddtrace.StartSpanOptio
opt := clientOptions.Options()
if opt.Addr == "FailoverClient" {
additionalTags = []ddtrace.StartSpanOption{
tracer.Tag("out.db", strconv.Itoa(opt.DB)),
tracer.Tag(ext.TargetDB, strconv.Itoa(opt.DB)),
}
} else {
host, port, err := net.SplitHostPort(opt.Addr)
Expand All @@ -89,7 +89,7 @@ func additionalTagOptions(client redis.UniversalClient) []ddtrace.StartSpanOptio
additionalTags = []ddtrace.StartSpanOption{
tracer.Tag(ext.TargetHost, host),
tracer.Tag(ext.TargetPort, port),
tracer.Tag("out.db", strconv.Itoa(opt.DB)),
tracer.Tag(ext.TargetDB, strconv.Itoa(opt.DB)),
}
}
} else if clientOptions, ok := client.(clusterOptions); ok {
Expand Down
35 changes: 35 additions & 0 deletions contrib/valkey-go/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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"

"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/tracer"
)

// To start tracing Valkey, simply create a new client using the library and continue
// using as you normally would.
func Example() {
tracer.Start()
defer tracer.Stop()

vk, err := valkeytrace.NewClient(valkey.ClientOption{
InitAddress: []string{"localhost:6379"},
})
if err != nil {
log.Fatal(err)
return
}

if err := vk.Do(context.Background(), vk.B().Set().Key("key").Value("value").Build()).Error(); err != nil {
log.Fatal(err)
return
}
}
42 changes: 42 additions & 0 deletions contrib/valkey-go/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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

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

type config struct {
rawCommand bool
serviceName string
}

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

func defaultConfig() *config {
return &config{
// Do not include the raw command by default since it could contain sensitive data.
rawCommand: internal.BoolEnv("DD_TRACE_VALKEY_RAW_COMMAND", false),
serviceName: namingschema.ServiceName(defaultServiceName),
}
}

// WithRawCommand can be used to set a tag `valkey.raw_command` in the created spans (disabled by default).
// Warning: please note the datadog-agent currently does not support obfuscation for this tag, so use this at your own risk.
func WithRawCommand(rawCommand bool) Option {
return func(cfg *config) {
cfg.rawCommand = rawCommand
}
}

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

0 comments on commit 5095868

Please sign in to comment.