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

parametric: avoid redefining otel SpanKind and StatusCode #3543

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ scp==0.14.5
ddapm-test-agent==1.18.0
filelock==3.12.2 # for parametric tests
dictdiffer==0.9.0 # for parametric tests
opentelemetry-api==1.27.0 # for parametric tests


#On Boarding requirements
Expand Down
2 changes: 1 addition & 1 deletion tests/parametric/test_otel_api_interoperability.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from utils import bug, missing_feature, irrelevant, context, scenarios, features
from utils.dd_constants import SpanKind
from opentelemetry.trace import SpanKind
from utils.parametric.spec.trace import find_trace, find_span, retrieve_span_links, find_only_span, find_root_span

# this global mark applies to all tests in this file.
Expand Down
4 changes: 2 additions & 2 deletions tests/parametric/test_otel_span_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from typing import Union
from utils.parametric._library_client import Link
from utils.dd_constants import StatusCode
from utils.dd_constants import SpanKind
from opentelemetry.trace import StatusCode
from opentelemetry.trace import SpanKind
from utils.parametric.spec.trace import find_span
from utils.parametric.spec.trace import find_trace
from utils.parametric.spec.trace import retrieve_span_links
Expand Down
4 changes: 2 additions & 2 deletions tests/parametric/test_parametric_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from utils.parametric.spec.trace import retrieve_span_links
from utils.parametric.spec.trace import find_only_span
from utils import irrelevant, bug, scenarios, features, context
from utils.dd_constants import SpanKind
from utils.dd_constants import StatusCode
from opentelemetry.trace import SpanKind
from opentelemetry.trace import StatusCode
from utils.parametric._library_client import Link


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ private static async Task<string> OtelStartSpan(HttpRequest request)
{
switch (Convert.ToInt64(spanKind))
{
case 1:
case 0:
kind = ActivityKind.Internal;
break;
case 2:
case 1:
kind = ActivityKind.Server;
break;
case 3:
case 2:
kind = ActivityKind.Client;
break;
case 4:
case 3:
kind = ActivityKind.Producer;
break;
case 5:
case 4:
kind = ActivityKind.Consumer;
break;
default:
Expand Down
5 changes: 4 additions & 1 deletion utils/build/docker/golang/parametric/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ func (s *apmClientServer) OtelStartSpan(args OtelStartSpanArgs) (OtelStartSpanRe
}
var otelOpts []otel_trace.SpanStartOption
if args.SpanKind != nil {
otelOpts = append(otelOpts, otel_trace.WithSpanKind(otel_trace.ValidateSpanKind(otel_trace.SpanKind(*args.SpanKind))))
// SpanKindUnspecified is not supported by the parametric interface.
// SpanKind needs to be remapped (incremented by 1) to match the expected value golang value.
// https://github.com/open-telemetry/opentelemetry-go/blob/e98ef1bfdb4cc413a019ebdb64988e17bb331942/trace/span.go#L120
otelOpts = append(otelOpts, otel_trace.WithSpanKind(otel_trace.ValidateSpanKind(otel_trace.SpanKind(*args.SpanKind + 1))))
mabdinur marked this conversation as resolved.
Show resolved Hide resolved
}
if t := args.Timestamp; t != nil {
tm := time.UnixMicro(*t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public OpenTelemetryController() {

private static SpanKind parseSpanKindNumber(int spanKindNumber) {
return switch (spanKindNumber) {
case 1 -> INTERNAL;
case 2 -> SERVER;
case 3 -> CLIENT;
case 4 -> PRODUCER;
case 5 -> CONSUMER;
case 0 -> INTERNAL;
case 1 -> SERVER;
case 2 -> CLIENT;
case 3 -> PRODUCER;
case 4 -> CONSUMER;
default -> null;
};
}
Expand Down
12 changes: 10 additions & 2 deletions utils/build/docker/nodejs/parametric/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tracer.use('dns', false)
const SpanContext = require('dd-trace/packages/dd-trace/src/opentracing/span_context')
const OtelSpanContext = require('dd-trace/packages/dd-trace/src/opentelemetry/span_context')

const { trace, ROOT_CONTEXT } = require('@opentelemetry/api')
const { trace, ROOT_CONTEXT, SpanKind } = require('@opentelemetry/api')
const { millisToHrTime } = require('@opentelemetry/core')

const { TracerProvider } = tracer
Expand Down Expand Up @@ -37,6 +37,14 @@ const otelStatusCodes = {
'ERROR': 2
}

const otelSpanKinds = {
0: SpanKind.INTERNAL,
1: SpanKind.SERVER,
2: SpanKind.CLIENT,
3: SpanKind.PRODUCER,
4: SpanKind.CONSUMER
}

const spans = new Map()
const ddContext = new Map()
const otelSpans = new Map()
Expand Down Expand Up @@ -177,7 +185,7 @@ app.post('/trace/otel/start_span', (req, res) => {
}
const span = otelTracer.startSpan(request.name, {
type: request.type,
kind: kind,
kind: otelSpanKinds[request.span_kind],
attributes: request.attributes,
links,
startTime: microLongToHrTime(request.timestamp)
Expand Down
10 changes: 5 additions & 5 deletions utils/build/docker/php/parametric/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ function largeBaseConvert($numString, $fromBase, $toBase)

function remappedSpanKind($spanKind) {
switch ($spanKind) {
case 1: // SK_INTERNAL
case 0: // SK_INTERNAL
return SpanKind::KIND_INTERNAL;
case 2: // SK_SERVER
case 1: // SK_SERVER
return SpanKind::KIND_SERVER;
case 3: // SK_CLIENT
case 2: // SK_CLIENT
return SpanKind::KIND_CLIENT;
case 4: // SK_PRODUCER
case 3: // SK_PRODUCER
return SpanKind::KIND_PRODUCER;
case 5: // SK_CONSUMER
case 4: // SK_CONSUMER
return SpanKind::KIND_CONSUMER;
default:
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,10 @@ def otel_start_span(args: OtelStartSpanArgs):
span_context = otel_spans[parent_id].get_span_context()
links.append(opentelemetry.trace.Link(span_context, link.get("attributes")))

# parametric tests expect span kind to be 0 for internal, 1 for server, 2 for client, ....
# while parametric tests set 0 for unset, 1 internal, 2 for server, 3 for client, ....
span_kind_int = (args.span_kind or 1) - 1
with otel_tracer.start_as_current_span(
args.name,
context=set_span_in_context(parent_span),
kind=SpanKind(span_kind_int),
kind=SpanKind(args.span_kind or 0),
attributes=args.attributes,
links=links,
# parametric tests expect timestamps to be set in microseconds (required by go)
Expand Down
10 changes: 5 additions & 5 deletions utils/build/docker/ruby/parametric/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def otel_tracer
end

OTEL_SPAN_KIND = {
1 => :internal,
2 => :server,
3 => :client,
4 => :producer,
5 => :consumer
0 => :internal,
1 => :server,
2 => :client,
3 => :producer,
4 => :consumer
}

# Ensure output is always flushed, to prevent a forced shutdown from losing all logs.
Expand Down
41 changes: 2 additions & 39 deletions utils/dd_constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from enum import IntEnum
from opentelemetry.trace import SpanKind # pylint: disable=W0611
from opentelemetry.trace import StatusCode # pylint: disable=W0611


# Key used in the metrics map to indicate tracer sampling priority
Expand Down Expand Up @@ -61,42 +63,3 @@ class Capabilities(IntEnum):
ASM_SESSION_FINGERPRINT = 33
ASM_NETWORK_FINGERPRINT = 34
ASM_HEADER_FINGERPRINT = 35


class SpanKind(IntEnum):
"""Specifies additional details on how this span relates to its parent span.
"""

#: Default value. Indicates that the span is used internally in the
# application.
INTERNAL = 1

#: Indicates that the span describes an operation that handles a remote
# request.
SERVER = 2

#: Indicates that the span describes a request to some remote service.
CLIENT = 3

#: Indicates that the span describes a producer sending a message to a
#: broker. Unlike client and server, there is usually no direct critical
#: path latency relationship between producer and consumer spans.
PRODUCER = 4

#: Indicates that the span describes a consumer receiving a message from a
#: broker. Unlike client and server, there is usually no direct critical
#: path latency relationship between producer and consumer spans.
CONSUMER = 5


class StatusCode(IntEnum):
"""Represents the canonical set of status codes of a finished Span."""

UNSET = 0
"""The default status."""

OK = 1
"""The operation has been validated by an Application developer or Operator to have completed successfully."""

ERROR = 2
"""The operation contains an error."""
2 changes: 1 addition & 1 deletion utils/parametric/_library_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import pytest
from _pytest.outcomes import Failed
import requests
from opentelemetry.trace import SpanKind, StatusCode
from utils import context

from utils.dd_constants import SpanKind, StatusCode
from utils.parametric.spec.otel_trace import OtelSpanContext
from utils.tools import logger

Expand Down