From 50dab2208f1b14a9809a423220a9f1d5804c87ef Mon Sep 17 00:00:00 2001 From: Terrell Broomer Date: Fri, 7 Jul 2023 06:12:13 +0000 Subject: [PATCH 1/6] add functionality for --force-parent-span-id --- README.md | 1 + data_for_test.go | 10 ++++++---- otelcli/root.go | 3 ++- otlpclient/config.go | 2 ++ otlpclient/protobuf_span.go | 6 +++++- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index aab5c86..d250593 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,7 @@ then config file, then environment variables. | --attrs | OTEL_CLI_ATTRIBUTES | span_attributes | k=v,a=b | | --force-trace-id | OTEL_CLI_FORCE_TRACE_ID | force_trace_id | 00112233445566778899aabbccddeeff | | --force-span-id | OTEL_CLI_FORCE_SPAN_ID | force_span_id | beefcafefacedead | +| --force-parent-span-id | OTEL_CLI_FORCE_PARENT_SPAN_ID | force_parent_span_id | parentbeefcafede | | --tp-required | OTEL_CLI_TRACEPARENT_REQUIRED | traceparent_required | false | | --tp-carrier | OTEL_CLI_CARRIER_FILE | traceparent_carrier_file | filename.txt | | --tp-ignore-env | OTEL_CLI_IGNORE_ENV | traceparent_ignore_env | false | diff --git a/data_for_test.go b/data_for_test.go index 07c52ad..f41b817 100644 --- a/data_for_test.go +++ b/data_for_test.go @@ -922,23 +922,25 @@ var suites = []FixtureSuite{ }, }, }, - // --force-trace-id and --force-span-id allow setting/forcing custom trace & span ids + // --force-trace-id, --force-span-id and --force-parent-span-id allow setting/forcing custom trace, span and parent span ids { { - Name: "forced trace & span ids", + Name: "forced trace, span and parent span ids", Config: FixtureConfig{ CliArgs: []string{ "status", "--endpoint", "{{endpoint}}", "--force-trace-id", "00112233445566778899aabbccddeeff", "--force-span-id", "beefcafefacedead", + "--force-parent-span-id", "parentbeefcafede", }, }, Expect: Results{ Config: otlpclient.DefaultConfig().WithEndpoint("{{endpoint}}"), SpanData: map[string]string{ - "trace_id": "00112233445566778899aabbccddeeff", - "span_id": "beefcafefacedead", + "trace_id": "00112233445566778899aabbccddeeff", + "span_id": "beefcafefacedead", + "parent_span_id": "parentbeefcafede", }, SpanCount: 1, Diagnostics: otlpclient.Diagnostics{ diff --git a/otelcli/root.go b/otelcli/root.go index 27fe7f3..5882977 100644 --- a/otelcli/root.go +++ b/otelcli/root.go @@ -150,9 +150,10 @@ func addSpanParams(cmd *cobra.Command, config *otlpclient.Config) { // --kind / -k cmd.Flags().StringVarP(&config.Kind, "kind", "k", defaults.Kind, "set the trace kind, e.g. internal, server, client, producer, consumer") - // expert options: --force-trace-id, --force-span-id allow setting custom trace & span ids + // expert options: --force-trace-id, --force-span-id, --force-parent-span-id allow setting custom trace, span and parent span ids cmd.Flags().StringVar(&config.ForceTraceId, "force-trace-id", defaults.ForceTraceId, "expert: force the trace id to be the one provided in hex") cmd.Flags().StringVar(&config.ForceSpanId, "force-span-id", defaults.ForceSpanId, "expert: force the span id to be the one provided in hex") + cmd.Flags().StringVar(&config.ForceParentSpanId, "force-parent-span-id", defaults.ForceParentSpanId, "expert: force the parent span id to be the one provided in hex") addSpanStatusParams(cmd, config) } diff --git a/otlpclient/config.go b/otlpclient/config.go index 62565e0..be96b48 100644 --- a/otlpclient/config.go +++ b/otlpclient/config.go @@ -42,6 +42,7 @@ func DefaultConfig() Config { Kind: "client", ForceTraceId: "", ForceSpanId: "", + ForceParentSpanId: "", Attributes: map[string]string{}, TraceparentCarrierFile: "", TraceparentIgnoreEnv: false, @@ -91,6 +92,7 @@ type Config struct { StatusCode string `json:"span_status_code" env:"OTEL_CLI_STATUS_CODE"` StatusDescription string `json:"span_status_description" env:"OTEL_CLI_STATUS_DESCRIPTION"` ForceSpanId string `json:"force_span_id" env:"OTEL_CLI_FORCE_SPAN_ID"` + ForceParentSpanId string `json:"force_parent_span_id" env:"OTEL_CLI_FORCE_PARENT_SPAN_ID"` ForceTraceId string `json:"force_trace_id" env:"OTEL_CLI_FORCE_TRACE_ID"` TraceparentCarrierFile string `json:"traceparent_carrier_file" env:"OTEL_CLI_CARRIER_FILE"` diff --git a/otlpclient/protobuf_span.go b/otlpclient/protobuf_span.go index f8138ea..872712a 100644 --- a/otlpclient/protobuf_span.go +++ b/otlpclient/protobuf_span.go @@ -95,7 +95,7 @@ func NewProtobufSpanWithConfig(c Config) *tracepb.Span { span.SpanId = emptySpanId } - // --force-trace-id and --force-span-id let the user set their own trace & span ids + // --force-trace-id, --force-span-id and --force-parent-span-id let the user set their own trace, span & parent span ids // these work in non-recording mode and will stomp trace id from the traceparent var err error if c.ForceTraceId != "" { @@ -106,6 +106,10 @@ func NewProtobufSpanWithConfig(c Config) *tracepb.Span { span.SpanId, err = parseHex(c.ForceSpanId, 8) c.SoftFailIfErr(err) } + if c.ForceParentSpanId != "" { + span.ParentSpanId, err = parseHex(c.ForceParentSpanId, 8) + c.SoftFailIfErr(err) + } SetSpanStatus(span, c) From dc050174632a3acd3f27b7e1b04e8cc06f2cfc4d Mon Sep 17 00:00:00 2001 From: Terrell Broomer Date: Fri, 14 Jul 2023 14:50:01 +0900 Subject: [PATCH 2/6] use hex instead of string --- README.md | 2 +- data_for_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d250593..8d8b6bc 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ then config file, then environment variables. | --attrs | OTEL_CLI_ATTRIBUTES | span_attributes | k=v,a=b | | --force-trace-id | OTEL_CLI_FORCE_TRACE_ID | force_trace_id | 00112233445566778899aabbccddeeff | | --force-span-id | OTEL_CLI_FORCE_SPAN_ID | force_span_id | beefcafefacedead | -| --force-parent-span-id | OTEL_CLI_FORCE_PARENT_SPAN_ID | force_parent_span_id | parentbeefcafede | +| --force-parent-span-id | OTEL_CLI_FORCE_PARENT_SPAN_ID | force_parent_span_id | p4r3ntb33fc4f3d3 | | --tp-required | OTEL_CLI_TRACEPARENT_REQUIRED | traceparent_required | false | | --tp-carrier | OTEL_CLI_CARRIER_FILE | traceparent_carrier_file | filename.txt | | --tp-ignore-env | OTEL_CLI_IGNORE_ENV | traceparent_ignore_env | false | diff --git a/data_for_test.go b/data_for_test.go index f41b817..22cf378 100644 --- a/data_for_test.go +++ b/data_for_test.go @@ -932,7 +932,7 @@ var suites = []FixtureSuite{ "--endpoint", "{{endpoint}}", "--force-trace-id", "00112233445566778899aabbccddeeff", "--force-span-id", "beefcafefacedead", - "--force-parent-span-id", "parentbeefcafede", + "--force-parent-span-id", "p4r3ntb33fc4f3d3", }, }, Expect: Results{ @@ -940,7 +940,7 @@ var suites = []FixtureSuite{ SpanData: map[string]string{ "trace_id": "00112233445566778899aabbccddeeff", "span_id": "beefcafefacedead", - "parent_span_id": "parentbeefcafede", + "parent_span_id": "p4r3ntb33fc4f3d3", }, SpanCount: 1, Diagnostics: otlpclient.Diagnostics{ From 40d07bf5612a83db0ff4073fa8998e6a0ab1e5ef Mon Sep 17 00:00:00 2001 From: Amy Tobey Date: Fri, 14 Jul 2023 11:36:41 -0400 Subject: [PATCH 3/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d8b6bc..2d8afd3 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ then config file, then environment variables. | --attrs | OTEL_CLI_ATTRIBUTES | span_attributes | k=v,a=b | | --force-trace-id | OTEL_CLI_FORCE_TRACE_ID | force_trace_id | 00112233445566778899aabbccddeeff | | --force-span-id | OTEL_CLI_FORCE_SPAN_ID | force_span_id | beefcafefacedead | -| --force-parent-span-id | OTEL_CLI_FORCE_PARENT_SPAN_ID | force_parent_span_id | p4r3ntb33fc4f3d3 | +| --force-parent-span-id | OTEL_CLI_FORCE_PARENT_SPAN_ID | force_parent_span_id | eeeeeeb33fc4f3d3 | | --tp-required | OTEL_CLI_TRACEPARENT_REQUIRED | traceparent_required | false | | --tp-carrier | OTEL_CLI_CARRIER_FILE | traceparent_carrier_file | filename.txt | | --tp-ignore-env | OTEL_CLI_IGNORE_ENV | traceparent_ignore_env | false | From 351636977a91a01a0b21ba27b9b94a2375604618 Mon Sep 17 00:00:00 2001 From: Amy Tobey Date: Fri, 14 Jul 2023 11:37:10 -0400 Subject: [PATCH 4/6] Update data_for_test.go --- data_for_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_for_test.go b/data_for_test.go index 22cf378..7ae3654 100644 --- a/data_for_test.go +++ b/data_for_test.go @@ -940,7 +940,7 @@ var suites = []FixtureSuite{ SpanData: map[string]string{ "trace_id": "00112233445566778899aabbccddeeff", "span_id": "beefcafefacedead", - "parent_span_id": "p4r3ntb33fc4f3d3", + "parent_span_id": "e4e3eeb33fc4f3d3", }, SpanCount: 1, Diagnostics: otlpclient.Diagnostics{ From 077dbd20f960969885f36b51d25091cb83230b4f Mon Sep 17 00:00:00 2001 From: Amy Tobey Date: Fri, 14 Jul 2023 11:37:43 -0400 Subject: [PATCH 5/6] Update data_for_test.go --- data_for_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_for_test.go b/data_for_test.go index 7ae3654..3f2662f 100644 --- a/data_for_test.go +++ b/data_for_test.go @@ -932,7 +932,7 @@ var suites = []FixtureSuite{ "--endpoint", "{{endpoint}}", "--force-trace-id", "00112233445566778899aabbccddeeff", "--force-span-id", "beefcafefacedead", - "--force-parent-span-id", "p4r3ntb33fc4f3d3", + "--force-parent-span-id", "e4e3eeb33fc4f3d3", }, }, Expect: Results{ From 46aa86a84b49186bf14ee2c9febc64c9f09ce867 Mon Sep 17 00:00:00 2001 From: Amy Tobey Date: Fri, 14 Jul 2023 11:46:00 -0400 Subject: [PATCH 6/6] rename stringmap parent -> parent_span_id fixes test --- data_for_test.go | 3 ++- otlpclient/protobuf_span.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/data_for_test.go b/data_for_test.go index 3f2662f..dd63f67 100644 --- a/data_for_test.go +++ b/data_for_test.go @@ -930,6 +930,7 @@ var suites = []FixtureSuite{ CliArgs: []string{ "status", "--endpoint", "{{endpoint}}", + "--fail", "--force-trace-id", "00112233445566778899aabbccddeeff", "--force-span-id", "beefcafefacedead", "--force-parent-span-id", "e4e3eeb33fc4f3d3", @@ -944,7 +945,7 @@ var suites = []FixtureSuite{ }, SpanCount: 1, Diagnostics: otlpclient.Diagnostics{ - NumArgs: 7, + NumArgs: 10, IsRecording: true, DetectedLocalhost: true, ParsedTimeoutMs: 1000, diff --git a/otlpclient/protobuf_span.go b/otlpclient/protobuf_span.go index 872712a..c5793e9 100644 --- a/otlpclient/protobuf_span.go +++ b/otlpclient/protobuf_span.go @@ -301,7 +301,7 @@ func SpanToStringMap(span *tracepb.Span, rss *tracepb.ResourceSpans) map[string] return map[string]string{ "trace_id": hex.EncodeToString(span.GetTraceId()), "span_id": hex.EncodeToString(span.GetSpanId()), - "parent": hex.EncodeToString(span.GetParentSpanId()), + "parent_span_id": hex.EncodeToString(span.GetParentSpanId()), "name": span.Name, "kind": SpanKindIntToString(span.GetKind()), "start": strconv.FormatUint(span.StartTimeUnixNano, 10),