|
| 1 | +// Unless explicitly stated otherwise all files in this repository are licensed |
| 2 | +// under the Apache License Version 2.0. |
| 3 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 4 | +// Copyright 2024 Datadog, Inc. |
| 5 | + |
| 6 | +package main |
| 7 | + |
| 8 | +import ( |
| 9 | + "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" |
| 10 | +) |
| 11 | + |
| 12 | +func main() { |
| 13 | + tracer.Start() |
| 14 | + defer tracer.Stop() |
| 15 | + |
| 16 | + parent := tracer.StartSpan("parent") |
| 17 | + defer parent.Finish() |
| 18 | + |
| 19 | + extraOpt := tracer.ResourceName("resource") |
| 20 | + |
| 21 | + // Simple ChildOf usage |
| 22 | + child := tracer.StartSpan("child", tracer.ChildOf(parent.Context())) // want `use StartChild instead of StartSpan with ChildOf` |
| 23 | + defer child.Finish() |
| 24 | + |
| 25 | + // ChildOf with additional options |
| 26 | + child2 := tracer.StartSpan("child2", tracer.ChildOf(parent.Context()), tracer.ResourceName("resource")) // want `use StartChild instead of StartSpan with ChildOf` |
| 27 | + defer child2.Finish() |
| 28 | + |
| 29 | + // ChildOf with non-call option (variable) |
| 30 | + child3 := tracer.StartSpan("child3", tracer.ChildOf(parent.Context()), extraOpt) // want `use StartChild instead of StartSpan with ChildOf` |
| 31 | + defer child3.Finish() |
| 32 | + |
| 33 | + // ChildOf with binary expression in option argument (now supported) |
| 34 | + child5 := tracer.StartSpan("child5", tracer.ChildOf(parent.Context()), tracer.ResourceName("a"+"b")) // want `use StartChild instead of StartSpan with ChildOf` |
| 35 | + defer child5.Finish() |
| 36 | + |
| 37 | + // ChildOf with a SpanContext (not a Span) - diagnostic but no fix |
| 38 | + parentCtx := parent.Context() |
| 39 | + child6 := tracer.StartSpan("child6", tracer.ChildOf(parentCtx)) // want `use StartChild instead of StartSpan with ChildOf` |
| 40 | + defer child6.Finish() |
| 41 | + |
| 42 | + // StartSpan with binary expression as opName - diagnostic but no fix |
| 43 | + suffix := "op" |
| 44 | + child7 := tracer.StartSpan("a"+suffix, tracer.ChildOf(parent.Context())) // want `use StartChild instead of StartSpan with ChildOf` |
| 45 | + defer child7.Finish() |
| 46 | + |
| 47 | + // ChildOf passed via variadic (ellipsis applies to ChildOf itself) - should not be rewritten |
| 48 | + parentOpts := []tracer.StartSpanOption{ |
| 49 | + tracer.ChildOf(parent.Context()), |
| 50 | + } |
| 51 | + child4 := tracer.StartSpan("child4", parentOpts...) |
| 52 | + defer child4.Finish() |
| 53 | +} |
0 commit comments