Skip to content
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

[Draft; don't merge] v1 as frontend of v2 #2607

Draft
wants to merge 199 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
199 commits
Select commit Hold shift + click to select a range
f406a87
wip
darccio Feb 14, 2024
2e2be33
ddtrace/tracer: use all exported functions as frontend for their v2 c…
darccio Feb 15, 2024
7a97334
ddtrace/tracer: remove unused code after conversion
darccio Feb 15, 2024
6119ca9
Merge remote-tracking branch 'origin/main' into vits
darccio Feb 15, 2024
f6dc6b7
go.mod: upgrade dd-trace-go & fix tests
darccio Feb 15, 2024
26eebd4
go.mod: upgrade dd-trace-go
darccio Feb 16, 2024
0a4f483
ddtrace/opentelemetry: use all exported functions as frontend for the…
darccio Feb 16, 2024
a96ebd3
ddtrace/opentelemetry: remove unused code after conversion
darccio Feb 16, 2024
4454b85
datastreams: use all exported functions as frontend for their v2 coun…
darccio Feb 16, 2024
c26938d
ddtrace/tracer: fix failing tests (to be squashed)
darccio Feb 16, 2024
f2b2c7d
profiler: use all exported functions as frontend for their v2 counter…
darccio Feb 19, 2024
655a99a
appsec: use all exported functions as frontend for their v2 counterparts
darccio Feb 19, 2024
acb90a8
ddtrace/tracer: fix failing tests (to be squashed)
darccio Feb 19, 2024
9ac02ee
contrib: use all exported functions and types as frontend for their v…
darccio Feb 19, 2024
ddd3268
contrib: remove unused code after conversion
darccio Feb 19, 2024
e453783
internal: remove unused code after conversion
darccio Feb 19, 2024
112d10a
profiler/internal: remove unused code after conversion
darccio Feb 19, 2024
688e227
internal/traceprof: remove unused code after conversion
darccio Feb 19, 2024
55ca241
contrib: fix failing tests (pending to squash)
darccio Feb 19, 2024
e31e95e
ddtrace/tracer: remove failing tests (pending to squash)
darccio Feb 19, 2024
5a15bca
internal/log: pass logger to v2
darccio Feb 19, 2024
7cbe4ab
internal/version: v1.999.0-rc.1
darccio Feb 20, 2024
9aabf03
internal/apps/setup-smoke-test: recover
darccio Feb 20, 2024
5710cef
profiler/upload: fix copyright header
darccio Feb 20, 2024
8bfcb1d
ddtrace/mocktracer: add MockspanV2Adapter to allow transparent operat…
darccio Feb 20, 2024
7eb723f
ddtrace/tracer: gracefully handle nil Span in ContextWithSpan
darccio Feb 20, 2024
de3213d
ddtrace/tracer: revert ContextWithSpan and SpanFromContext to be self…
darccio Feb 20, 2024
6a6f979
contrib/gorilla/mux: fix tests and mock v1 mockspan behaviour
darccio Feb 21, 2024
a0bbf07
internal/version: v1.999.0-rc.3
darccio Feb 21, 2024
c2a6279
ddtrace: support v1 behaviour for mock spans
darccio Feb 22, 2024
edfa0cc
go.mod: update dd-trace-go
darccio Feb 22, 2024
20d2279
internal/version: v1.999.0-rc.5
darccio Feb 22, 2024
3128d4c
ddtrace/tracer: remove extra ContextWithSpan call in StartSpanFromCon…
darccio Feb 22, 2024
007d72a
go.mod: update dd-trace-go
darccio Feb 22, 2024
5c94f45
internal/version: v1.999.0-rc.7
darccio Feb 23, 2024
f71a46a
ddtrace/mocktracer: fix OpenSpans
darccio Feb 23, 2024
e2610f8
go.mod: upgrade dd-trace-go/v2
darccio Feb 23, 2024
92b954c
internal/version: v1.999.0-rc.8
darccio Feb 23, 2024
27358ff
Merge remote-tracking branch 'origin/main' into vits
darccio Mar 4, 2024
285d5a9
Merge remote-tracking branch 'origin/main' into vits
darccio Mar 7, 2024
55323ef
go.mod: update to latests dd-trace-go/v2
darccio Mar 7, 2024
254f26c
ci: trigger
darccio Mar 7, 2024
a3ecf4a
ddtrace/mocktracer: small fixes for adapting to real tracer behaviour
darccio Mar 8, 2024
d843d2f
go.mod: upgrade dd-trace-go/v2
darccio Mar 8, 2024
f0418fb
contrib/aws/aws-sdk-go/aws: migrate contrib/aws/aws-sdk-go/aws to v2
darccio Mar 8, 2024
4e41abc
contrib/aws/aws-sdk-go-v2/aws: migrate contrib/aws/aws-sdk-go-v2/aws …
darccio Mar 8, 2024
c10f0c2
go.mod: upgrade dd-trace-go/v2 dependencies
darccio Mar 8, 2024
19c57ff
internal/version: v1.999.0-rc.9
darccio Mar 8, 2024
477e794
contrib/IBM/sarama.v1: migrate to v2
darccio Mar 8, 2024
e48294f
contrib/bradfitz/gomemcache: migrate to v2
darccio Mar 8, 2024
b44dad8
contrib/cloud.google.com/go/pubsub.v1: migrate to v2
darccio Mar 8, 2024
b631087
contrib/confluentinc/confluent-kafka-go: migrate to v2
darccio Mar 8, 2024
b6317ce
contrib/confluentinc/confluent-kafka-go.v2: migrate to v2
darccio Mar 10, 2024
0756777
contrib/database/sql/internal: remove unused code
darccio Mar 10, 2024
2f62e96
contrib/dimfeld/httptreemux.v5: migrate to v2
darccio Mar 10, 2024
e0eb1b2
contrib/elastic/go-elasticsearch.v6: migrate to v2
darccio Mar 10, 2024
42d7188
contrib/globalsign/mgo: migrate to v2
darccio Mar 10, 2024
544cde9
contrib/go-pg/pg.v10: migrate to v2
darccio Mar 10, 2024
c8cc4ef
contrib/go-redis/redis: migrate to v2
darccio Mar 10, 2024
8701484
contrib/go-redis/redis.v7: migrate to v2
darccio Mar 10, 2024
06cbb20
contrib/confluentinc/confluent-kafka-go: fix integration check
darccio Mar 10, 2024
65d19e3
contrib/go-redis/redis.v8: migrate to v2
darccio Mar 10, 2024
a4c3ecd
contrib/go.mongodb.org/mongo-driver: migrate to v2
darccio Mar 10, 2024
cda2976
contrib/internal: remove extranuous v2.go file
darccio Mar 10, 2024
124b409
contrib/gocql/gocql: migrate to v2
darccio Mar 10, 2024
3cb04b2
contrib/go.mongodb.org/mongo-driver: fix integration tests
darccio Mar 10, 2024
5edb819
contrib/gofiber/fiber.v2: migrate to v2
darccio Mar 10, 2024
e5529fc
contrib/gomodule/redigo: migrate to v2
darccio Mar 10, 2024
95e067a
contrib/google.golang.org/api/internal/tree: remove unused code
darccio Mar 10, 2024
a99c2f1
contrib/gorm.io/gorm.v1: migrate to v2
darccio Mar 10, 2024
2342d99
contrib/hashicorp/consul: migrate to v2
darccio Mar 10, 2024
751f4e2
contrib/jackc/pgx.v5: migrate to v2
darccio Mar 10, 2024
3f0d8a3
contrib/jmoiron/sqlx: migrate to v2
darccio Mar 10, 2024
6fa36c9
contrib/k8s.io/client-go: remove unused code
darccio Mar 10, 2024
5ff770a
contrib/miekg/dns: migrate to v2
darccio Mar 10, 2024
7ee262c
contrib/olivere/elastic: migrate to v2
darccio Mar 10, 2024
f441d8a
contrib/redis/go-redis.v9: migrate to v2
darccio Mar 11, 2024
069a708
contrib/segmentio/kafka.go.v0: migrate to v2
darccio Mar 11, 2024
8340083
contrib/Shopify/sarama: migrate to v2
darccio Mar 11, 2024
4b90fdf
contrib/sirupsen/logrus: migrate to v2
darccio Mar 11, 2024
62ca3fd
contrib/syndtr/goleveldb: migrate to v2
darccio Mar 11, 2024
acb7964
contrib/tidwall/buntdb: migrate to v2
darccio Mar 11, 2024
7947f7d
contrib/twitchtv/twirp: migrate to v2
darccio Mar 11, 2024
5a42a1b
contrib/urfave/negroni: migrate to v2
darccio Mar 11, 2024
257c3ab
contrib/aws/internal/tags: remove unused code
darccio Mar 11, 2024
eb033d8
appsec: remove unused code
darccio Mar 11, 2024
fd3917f
internal/{namingschema,globalconfig}: use v2/v1internal package to ad…
darccio Mar 11, 2024
0edd4c8
Merge remote-tracking branch 'origin/main' into vits
darccio Mar 11, 2024
d03e5c4
internal/version: remove unexpected character
darccio Mar 11, 2024
097a4e8
internal/telemetry: reduce API to bare minimum
darccio Mar 11, 2024
c54f08c
v1internal: remove accidentally commited files
darccio Mar 11, 2024
25d9c14
internal/telemetry: add minimal API
darccio Mar 11, 2024
ece6a1f
contrib/cloud.google.com/go/pubsub.v1: fix tests
darccio Mar 11, 2024
e3fe531
contrib: fix multiple tests
darccio Mar 11, 2024
1e2dbbb
go.mod: upgrade dd-trace-go/v2
darccio Mar 11, 2024
a0b43de
go.mod: upgrade dd-trace-go/v2 & aws-sdk-go-v2 contribs/deps
darccio Mar 11, 2024
76ce080
ddtrace/tracer: add missing benchmarks
darccio Mar 11, 2024
3ed2932
go.sum: go mod tidy
darccio Mar 11, 2024
bb7c6dd
contrib/graphql-go/graphql: fix contrib tests
darccio Mar 11, 2024
24e0ae6
internal/namingschema: fix TestServiceName
darccio Mar 11, 2024
2024063
contrib/net/http: avoid mocktracer in BenchmarkHttpServeTrace
darccio Mar 12, 2024
1b34ecb
ddtrace/internal: replace BuildStartSpanConfigV2 with ApplyV1Options
darccio Mar 12, 2024
04057f4
ddtrace/tracer: remove unused code
darccio Mar 12, 2024
4650bad
ddtrace/tracer: reset BenchmarkTracerAddSpans' timer before main loop
darccio Mar 12, 2024
25ec7b7
contrib: fix tests
darccio Mar 13, 2024
c8a0f6d
contrib/google.golang.org/grpc: fix TestSpanTree
darccio Mar 13, 2024
6cb3d86
go.sum: go mod tidy
darccio Mar 13, 2024
571b860
.github/workflows: run go mod tidy before appsec tests
darccio Mar 13, 2024
0a1b680
.github/workflows: run go mod tidy before docker appsec tests
darccio Mar 13, 2024
e4d7380
go.mod: go mod tidy
darccio Mar 13, 2024
0156f97
Merge remote-tracking branch 'origin/main' into vits
darccio Mar 13, 2024
f41c89d
go.mod: upgrade dd-trace-go/v2{,/contrib/99designs/gqlgen}
darccio Mar 13, 2024
06d39db
.github/workflows: run go mod tidy before appsec tests
darccio Mar 13, 2024
96c61ed
Merge remote-tracking branch 'origin' into vits
darccio Mar 13, 2024
805c59e
contrib/emicklei/go-restful.v3: change expected error message
darccio Mar 13, 2024
f84b530
contrib/google.golang.org/grpc: update TestIgnoredMethods
darccio Mar 13, 2024
dc97190
contrib/google.golang.org/grpc: update TestIgnoredMethods II
darccio Mar 13, 2024
15fa312
ddtrace/tracer: flush spans in genBigTraces
darccio Mar 13, 2024
38ce044
ddtrace/internal: introduce WrapSpan & ApplyV1FinishOptions
darccio Mar 14, 2024
68249e2
ddtrace/internal: reduce allocations in ApplyV1Options
darccio Mar 14, 2024
7207cb2
ddtrace/internal: reduce allocations in ApplyV1FinishOptions
darccio Mar 14, 2024
7c8966c
ddtrace/internal: memoize {Get,Set}GlobalTracer
darccio Mar 15, 2024
027b737
ddtrace/internal: make sure we return the concrete TracerV2Adapter va…
darccio Mar 15, 2024
6fa18c6
ddtrace/tracer: ignore tracer output
darccio Mar 15, 2024
161111e
contrib/net/http: ignore tracer output
darccio Mar 15, 2024
4844ec5
contrib/net/http: use pool to reduce memory allocations in TraceAndServe
darccio Mar 15, 2024
ee9a61b
go.mod: upgrade dd-trace-go/v2 & contribs
darccio Mar 15, 2024
c6c5c75
ddtrace/internal: fix TracerV2Adapter.StartSpan calling ApplyV1Options
darccio Mar 15, 2024
7a912d5
Merge remote-tracking branch 'origin' into vits
darccio Mar 19, 2024
20eb64a
chore: fix merge errors
darccio Mar 19, 2024
b072ed3
Merge remote-tracking branch 'origin' into vits
darccio Mar 19, 2024
84eed22
go.sum: force go mod cache miss
darccio Mar 19, 2024
06b443e
go.mod: upgrade dd-trace-go/v2 & contribs
darccio Mar 19, 2024
9c12d7b
.github/workflows/appsec.yml: test with default GOMODCACHE
darccio Mar 19, 2024
f284f36
Revert ".github/workflows/appsec.yml: test with default GOMODCACHE"
darccio Mar 19, 2024
bba4225
contrib/google.golang.org/grpc: update test
darccio Mar 20, 2024
7a9629a
contrib/google.golang.org/grpc: remove "_dd.measured" according to tr…
darccio Mar 20, 2024
390dd0b
ddtrace/mocktracer: reset global tracer on Stop
darccio Mar 20, 2024
9a1b86d
go.mod: upgrade dd-trace-go/v2 & contribs
darccio Mar 20, 2024
578878a
go.mod: upgrade dd-trace-go/v2 & contribs
darccio Mar 20, 2024
b5a7970
Reapply ".github/workflows/appsec.yml: test with default GOMODCACHE"
darccio Mar 20, 2024
6e6db3f
ddtrace: revert memoization of global tracer
darccio Mar 21, 2024
0855dc0
contrib/confluentinc/confluent-kafka-go/kafka: fix TestDeprecatedContext
darccio Mar 21, 2024
6934f7f
contrib/google.golang.org/grpc: go fmt (re: golang/go#58370)
darccio Mar 21, 2024
db804dc
Revert "contrib/confluentinc/confluent-kafka-go/kafka: fix TestDeprec…
darccio Mar 25, 2024
8db376f
.github/workflows: allow to manually run PR tests
darccio Mar 25, 2024
86f23da
.github/workflows: revert allowing to manually run PR tests
darccio Mar 25, 2024
7ba4a8b
Merge remote-tracking branch 'origin' into vits
darccio May 16, 2024
2091004
internal/appsec/config: remove test code that used telemetrytest
darccio May 17, 2024
94111d9
go.mod: go mod tidy
darccio May 17, 2024
eb5003f
v2: fix unnecessary code for vits
darccio May 17, 2024
265d09d
Merge remote-tracking branch 'origin' into vits
darccio Sep 17, 2024
52a5610
fix: make almost all tests green
darccio Sep 18, 2024
8a1d078
chore: comment profiler_version test in v1 shim
darccio Sep 18, 2024
3355619
chore: update dd-trace-go/v2
darccio Sep 18, 2024
3e43886
Merge remote-tracking branch 'origin' into vits
darccio Sep 18, 2024
1608989
chore(exectracetest): go mod tidy
darccio Sep 18, 2024
f5817ad
chore: make reviewdog happy
darccio Sep 18, 2024
1ca83b5
chore(go.mod): go mod tidy
darccio Oct 9, 2024
9e9a77a
refactor: reduce v1internal usage
darccio Oct 9, 2024
ca04959
chore: remove namingschematest stuff
darccio Oct 10, 2024
9698c25
fix: remove (almost) all references to v1internal
darccio Oct 10, 2024
507c79e
Merge remote-tracking branch 'origin' into vits
darccio Oct 11, 2024
8b37585
update to beta.5
hannahkm Nov 5, 2024
547b6ce
chore: set v1 shim dogfooding version tag
darccio Nov 5, 2024
71a33a5
chore: set v1 shim dogfooding version tag to v1.999.0-beta.5: aligned…
darccio Nov 5, 2024
4d783ee
fix: SQLCommentCarrier tests working with compatibility change in v2
darccio Nov 6, 2024
803bd8f
fix(ddtrace/tracer): allow beta versions in logging tests
darccio Nov 6, 2024
b6b2f63
chore: tag v1.999.0-beta.7
darccio Nov 6, 2024
4006612
chore(internal): go mod tidy
darccio Nov 6, 2024
9db84c8
chore: upgrade dd-trace-go/v2@v2.0.0-beta.8 and go mod tidy
darccio Nov 8, 2024
6911f43
chore: set version to v1.999.0-beta.8
darccio Nov 8, 2024
0f1c83a
chore: set version to v1.999.0-beta.9 and sync go.mod with v1.69.1
darccio Nov 8, 2024
569f12e
chore: go mod tidy internal apps
darccio Nov 9, 2024
298b3fa
chore: update to v2.0.0-beta.10
hannahkm Nov 13, 2024
261f0a7
chore(internal): upgrade to v1.999.0-beta.10 and tidy
hannahkm Nov 13, 2024
0031e91
chore: upgrade to v1.999.0-beta.11
hannahkm Nov 19, 2024
ac868e3
chore(internal): upgrade internal pkgs to beta.11
hannahkm Nov 19, 2024
bd92328
fix(ddtrace/tracer): account for MockspanV2Adapter in SetUser()
hannahkm Nov 19, 2024
1543ccf
Revert "fix(ddtrace/tracer): account for MockspanV2Adapter in SetUser()"
hannahkm Nov 20, 2024
9da18a2
fix(ddtrace/tracer): temporary workaround for tracer.SetUser
darccio Nov 25, 2024
2afbc4a
chore(ddtracer/tracer): add test for mockspan support in SetUser
darccio Nov 25, 2024
a3a4704
release: v1.999.0-beta.12
darccio Nov 25, 2024
effbed6
release: v1.999.0-beta.13
darccio Nov 25, 2024
a5052df
release: v1.999.0-beta.14
darccio Nov 25, 2024
7e63654
hack(profiler): filter nil options on the shim
darccio Nov 25, 2024
b1bf144
release: v1.999.0-beta.15
darccio Nov 25, 2024
a30b5c4
chore(profiler): add extra assertion to ensure we get the expected er…
darccio Nov 25, 2024
80bbee4
internal/version: v1.999.0-beta.16
darccio Nov 28, 2024
16a38ee
Merge branch 'main' into vits
darccio Nov 28, 2024
48b7034
chore: clean up unneeded code
darccio Nov 28, 2024
e5bac06
fix(contrib): small adaptations and bugs squashed
darccio Nov 29, 2024
f0fb594
Merge branch 'main' into vits
darccio Nov 29, 2024
d3b6c33
Merge from `main` into `vits`
darccio Nov 29, 2024
057e1a1
chore(internal/exectracetest): go mod tidy
darccio Nov 29, 2024
dcf1093
chore: upgrade to latest dd-trace-go v2-dev
darccio Dec 18, 2024
3b85006
fix(ddtrace/tracer): use v2.WithDogstatsdAddr instead of v2.WithDogst…
darccio Dec 18, 2024
6d47673
chore: upgrade to latest dd-trace-go v2-dev
darccio Dec 18, 2024
18fe13d
feat: upgrade to dd-trace-go v2.0.0-rc.2
darccio Dec 19, 2024
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
Prev Previous commit
Next Next commit
ddtrace/opentelemetry: remove unused code after conversion
darccio committed Feb 16, 2024

Verified

This commit was signed with the committer’s verified signature.
darccio Dario Castañé
commit a96ebd356a93ffc7a5bd493690d6d198807dc32e
305 changes: 0 additions & 305 deletions ddtrace/opentelemetry/span.go
Original file line number Diff line number Diff line change
@@ -6,321 +6,16 @@
package opentelemetry

import (
"encoding/binary"
"errors"
"strconv"
"strings"
"sync"

v2 "github.com/DataDog/dd-trace-go/v2/ddtrace/opentelemetry"
v2tracer "github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/internal"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"

"go.opentelemetry.io/otel/attribute"
otelcodes "go.opentelemetry.io/otel/codes"
oteltrace "go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
)

var _ oteltrace.Span = (*span)(nil)

type span struct {
noop.Span // https://pkg.go.dev/go.opentelemetry.io/otel/trace#hdr-API_Implementations
mu sync.RWMutex `msg:"-"` // all fields are protected by this RWMutex
DD tracer.Span
finished bool
attributes map[string]interface{}
spanKind oteltrace.SpanKind
finishOpts []tracer.FinishOption
statusInfo
*oteltracer
}

func (s *span) TracerProvider() oteltrace.TracerProvider { return s.oteltracer.provider }

func (s *span) SetName(name string) {
s.mu.Lock()
defer s.mu.Unlock()
s.attributes[ext.SpanName] = strings.ToLower(name)
}

func (s *span) End(options ...oteltrace.SpanEndOption) {
s.mu.Lock()
defer s.mu.Unlock()
if s.finished {
return
}
s.finished = true
for k, v := range s.attributes {
// if we find operation.name,
if k == "operation.name" || k == ext.SpanName {
// set it and keep track that it was set to ignore everything else
if name, ok := v.(string); ok {
s.attributes[ext.SpanName] = strings.ToLower(name)
}
}
}

// if no operation name was explicitly set,
// operation name has to be calculated from the attributes
if op, ok := s.attributes[ext.SpanName]; !ok || op == "" {
s.DD.SetTag(ext.SpanName, strings.ToLower(s.createOperationName()))
}

for k, v := range s.attributes {
s.DD.SetTag(k, v)
}
var finishCfg = oteltrace.NewSpanEndConfig(options...)
var opts []tracer.FinishOption
if s.statusInfo.code == otelcodes.Error {
s.DD.SetTag(ext.ErrorMsg, s.statusInfo.description)
opts = append(opts, tracer.WithError(errors.New(s.statusInfo.description)))
}
if t := finishCfg.Timestamp(); !t.IsZero() {
opts = append(opts, tracer.FinishTime(t))
}
if len(s.finishOpts) != 0 {
opts = append(opts, s.finishOpts...)
}
s.DD.Finish(opts...)
}

// EndOptions sets tracer.FinishOption on a given span to be executed when span is finished.
func EndOptions(sp oteltrace.Span, options ...tracer.FinishOption) {
cfg := internal.BuildFinishConfigV2(options...)
v2.EndOptions(sp, v2tracer.WithFinishConfig(cfg))
}

// SpanContext returns implementation of the oteltrace.SpanContext.
func (s *span) SpanContext() oteltrace.SpanContext {
ctx := s.DD.Context()
var traceID oteltrace.TraceID
var spanID oteltrace.SpanID
if w3cCtx, ok := ctx.(ddtrace.SpanContextW3C); ok {
traceID = w3cCtx.TraceID128Bytes()
} else {
log.Debug("Non-W3C context found in span, unable to get full 128 bit trace id")
uint64ToByte(ctx.TraceID(), traceID[:])
}
uint64ToByte(ctx.SpanID(), spanID[:])
config := oteltrace.SpanContextConfig{
TraceID: traceID,
SpanID: spanID,
}
s.extractTraceData(&config)
return oteltrace.NewSpanContext(config)
}

func (s *span) extractTraceData(c *oteltrace.SpanContextConfig) {
headers := tracer.TextMapCarrier{}
if err := tracer.Inject(s.DD.Context(), headers); err != nil {
return
}
state, err := oteltrace.ParseTraceState(headers["tracestate"])
if err != nil {
log.Debug("Couldn't parse tracestate: %v", err)
return
}
c.TraceState = state
parent := strings.Trim(headers["traceparent"], " \t-")
if len(parent) > 3 {
// checking the length to avoid panic when parsing
// The format of the traceparent is `-` separated string,
// where flags represents the propagated flags in the format of 2 hex-encoded digits at the end of the traceparent.
otelFlagLen := 2
if f, err := strconv.ParseUint(parent[len(parent)-otelFlagLen:], 16, 8); err != nil {
log.Debug("Couldn't parse traceparent: %v", err)
} else {
c.TraceFlags = oteltrace.TraceFlags(f)
}
}
// Remote indicates a remotely-created Span
c.Remote = true
}

func uint64ToByte(n uint64, b []byte) {
binary.BigEndian.PutUint64(b, n)
}

// IsRecording returns the recording state of the Span. It will return
// true if the Span is active and events can be recorded.
func (s *span) IsRecording() bool {
return !s.finished
}

type statusInfo struct {
code otelcodes.Code
description string
}

// SetStatus saves state of code and description indicating
// whether the span has recorded errors. This will be done by setting
// `error.message` tag on the span. If the code has been set to a higher
// value before (OK > Error > Unset), the code will not be changed.
// The code and description are set once when the span is finished.
func (s *span) SetStatus(code otelcodes.Code, description string) {
s.mu.Lock()
defer s.mu.Unlock()
if code >= s.statusInfo.code {
s.statusInfo = statusInfo{code, description}
}
}

// SetAttributes sets the key-value pairs as tags on the span.
// Every value is propagated as an interface.
// Some attribute keys are reserved and will be remapped to Datadog reserved tags.
// The reserved tags list is as follows:
// - "operation.name" (remapped to "span.name")
// - "analytics.event" (remapped to "_dd1.sr.eausr")
// - "service.name"
// - "resource.name"
// - "span.type"
//
// The list of reserved tags might be extended in the future.
// Any other non-reserved tags will be set as provided.
func (s *span) SetAttributes(kv ...attribute.KeyValue) {
s.mu.Lock()
defer s.mu.Unlock()
for _, kv := range kv {
if k, v := toReservedAttributes(string(kv.Key), kv.Value); k != "" {
s.attributes[k] = v
}
}
}

// toReservedAttributes recognizes a set of span attributes that have a special meaning.
// These tags should supersede other values.
func toReservedAttributes(k string, v attribute.Value) (string, interface{}) {
switch k {
case "operation.name":
if ops := strings.ToLower(v.AsString()); ops != "" {
return ext.SpanName, strings.ToLower(v.AsString())
}
// ignoring non-string values
return "", nil
case "analytics.event":
var rate int
if b, err := strconv.ParseBool(v.AsString()); err == nil && b {
rate = 1
} else if v.AsBool() {
rate = 1
} else {
rate = 0
}
return ext.EventSampleRate, rate
default:
return k, v.AsInterface()
}
}

func (s *span) createOperationName() string {
isClient := s.spanKind == oteltrace.SpanKindClient
isServer := s.spanKind == oteltrace.SpanKindServer

// http
if _, ok := s.attributes["http.request.method"]; ok {
switch s.spanKind {
case oteltrace.SpanKindServer:
return "http.server.request"
case oteltrace.SpanKindClient:
return "http.client.request"
}
}

// database
if v, ok := s.valueFromAttributes("db.system"); ok && isClient {
return v + ".query"
}

// messaging

system, systemOk := s.valueFromAttributes("messaging.system")
op, opOk := s.valueFromAttributes("messaging.operation")
if systemOk && opOk {
switch s.spanKind {
case oteltrace.SpanKindClient, oteltrace.SpanKindServer,
oteltrace.SpanKindConsumer, oteltrace.SpanKindProducer:
return system + "." + op
}
}

// RPC & AWS
rpcValue, isRPC := s.valueFromAttributes("rpc.system")
isAws := isRPC && (rpcValue == "aws-api")
// AWS client
if isAws && isClient {
if service, ok := s.valueFromAttributes("rpc.service"); ok {
return "aws." + service + ".request"
}
return "aws.client.request"
}
// RPC client
if isRPC && isClient {
return rpcValue + ".client.request"
}
// RPC server
if isRPC && isServer {
return rpcValue + ".server.request"
}

// FAAS client
provider, pOk := s.valueFromAttributes("faas.invoked_provider")
invokedName, inOk := s.valueFromAttributes("faas.invoked_name")
if pOk && inOk && isClient {
return provider + "." + invokedName + ".invoke"
}

// FAAS server
trigger, tOk := s.valueFromAttributes("faas.trigger")
if tOk && isServer {
return trigger + ".invoke"
}

// Graphql
if _, ok := s.valueFromAttributes("graphql.operation.type"); ok {
return "graphql.server.request"
}

// if nothing matches, checking for generic http server/client
protocol, pOk := s.valueFromAttributes("network.protocol.name")
if isServer {
if pOk {
return protocol + ".server.request"
}
return "server.request"
} else if isClient {
if pOk {
return protocol + ".client.request"
}
return "client.request"
}

if s.spanKind != 0 {
return s.spanKind.String()
}
// no span kind was set/detected, so span kind will be set to Internal explicitly.
s.attributes[ext.SpanKind] = oteltrace.SpanKindInternal
return oteltrace.SpanKindInternal.String()
}

func (s *span) valueFromAttributes(key string) (string, bool) {
v, ok := s.attributes[key]
if !ok {
return "", false
}
attr, ok := v.(attribute.Value)
if ok {
if s := strings.ToLower(attr.AsString()); s != "" {
return s, true
}
return "", false
}
if s := v.(string); s != "" {
return strings.ToLower(s), true
}
return "", false
}
89 changes: 0 additions & 89 deletions ddtrace/opentelemetry/telemetry_test.go

This file was deleted.

133 changes: 0 additions & 133 deletions ddtrace/opentelemetry/tracer.go

This file was deleted.

5 changes: 5 additions & 0 deletions ddtrace/opentelemetry/tracer_test.go
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ package opentelemetry

import (
"context"
"encoding/binary"
"fmt"
"sync"
"testing"
@@ -68,6 +69,10 @@ func TestSpanWithNewRoot(t *testing.T) {
assert.NotEqual(parentBytes, child.SpanContext().TraceID())
}

func uint64ToByte(n uint64, b []byte) {
binary.BigEndian.PutUint64(b, n)
}

func TestSpanWithoutNewRoot(t *testing.T) {
assert := assert.New(t)
otel.SetTracerProvider(NewTracerProvider())