-
Notifications
You must be signed in to change notification settings - Fork 15
test(otel): cover otlp trace headers and protocol #7795
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
Open
MilanGarnier
wants to merge
10
commits into
main
Choose a base branch
from
milan.garnier/test-otel-otlp-trace-settings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+261
−0
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c7b6a9e
test(otel): cover otlp trace headers and protocol
MilanGarnier f3919af
test(otel): classify otlp trace setting failures
MilanGarnier ceca8f7
test(dotnet): mark otlp trace defaults as bugs
MilanGarnier e416a11
test(dotnet): track otlp trace defaults under audit epic
MilanGarnier 9a9120f
chore: merge main into otlp trace settings
MilanGarnier bfdf125
test(otel): inline otlp trace header parameters
MilanGarnier eea6b7c
chore: merge main into otlp trace settings branch
MilanGarnier 57f9747
Merge branch 'main' into milan.garnier/test-otel-otlp-trace-settings
MilanGarnier 4085484
Merge branch 'main' into milan.garnier/test-otel-otlp-trace-settings
MilanGarnier 335670d
Merge branch 'main' into milan.garnier/test-otel-otlp-trace-settings
MilanGarnier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
tests/parametric/otel_env_vars/test_otel_exporter_otlp_traces_headers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| from tests.parametric.conftest import APMLibrary | ||
| from utils import features, pytest, scenarios | ||
| from utils.docker_fixtures import TestAgentAPI | ||
| from utils.docker_fixtures._test_agent import AgentRequest | ||
|
|
||
|
|
||
| VARIABLE = "OTEL_EXPORTER_OTLP_TRACES_HEADERS" | ||
|
|
||
| BASE_ENVIRONMENT = { | ||
| "DD_TRACE_AGENT_PROTOCOL_VERSION": None, | ||
| "DD_TRACE_ENABLED": None, | ||
| "DD_TRACE_OTEL_ENABLED": "true", | ||
| "OTEL_EXPORTER_OTLP_HEADERS": "dd-protocol=otlp,dd-otlp-path=agent", | ||
| "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL": "http/protobuf", | ||
| "OTEL_TRACES_EXPORTER": "otlp", | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def _trace_export_endpoint( | ||
| library_env: dict[str, str], | ||
| test_agent: TestAgentAPI, | ||
| test_agent_otlp_http_port: int, | ||
| ) -> None: | ||
| library_env["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = ( | ||
| f"http://{test_agent.container_name}:{test_agent_otlp_http_port}/v1/traces" | ||
| ) | ||
|
|
||
|
|
||
| def _trace_request(test_agent: TestAgentAPI, test_library: APMLibrary) -> AgentRequest: | ||
| with test_library as library: | ||
| with library.dd_start_span(name="otel-otlp-traces-headers"): | ||
| pass | ||
| library.dd_flush() | ||
|
|
||
| requests = [request for request in test_agent.requests() if request["url"].endswith("/v1/traces")] | ||
| assert requests, f"Expected OTLP trace request, got {test_agent.requests()}" | ||
| return requests[0] | ||
|
|
||
|
|
||
| def _request_headers(request: AgentRequest) -> dict[str, str]: | ||
| return {name.lower(): value for name, value in request["headers"].items()} | ||
|
|
||
|
|
||
| def _assert_routing_headers(headers: dict[str, str]) -> None: | ||
| assert headers.get("dd-protocol") == "otlp" | ||
| assert headers.get("dd-otlp-path") == "agent" | ||
|
|
||
|
|
||
| @scenarios.parametric | ||
| @features.otel_exporter_otlp_traces_headers | ||
| class Test_OTEL_EXPORTER_OTLP_TRACES_HEADERS: | ||
| @pytest.mark.parametrize( | ||
| ("library_env", "expected_headers"), | ||
| [ | ||
| pytest.param( | ||
| { | ||
| **BASE_ENVIRONMENT, | ||
| VARIABLE: "dd-protocol=otlp,dd-otlp-path=agent,header-one=value-one,header-two=value-two", | ||
| }, | ||
| {"header-one": "value-one", "header-two": "value-two"}, | ||
| id="two-header-pairs", | ||
| ), | ||
| ], | ||
| ) | ||
| def test_header_pairs_are_sent_on_trace_export( | ||
| self, | ||
| test_agent: TestAgentAPI, | ||
| test_library: APMLibrary, | ||
| *, | ||
| expected_headers: dict[str, str], | ||
| ) -> None: | ||
| headers = _request_headers(_trace_request(test_agent, test_library)) | ||
| _assert_routing_headers(headers) | ||
| for name, value in expected_headers.items(): | ||
| assert headers.get(name) == value, f"Expected {name}={value}, got {headers}" | ||
|
|
||
| @pytest.mark.parametrize("library_env", [pytest.param({**BASE_ENVIRONMENT}, id="unset")]) | ||
| def test_unset_uses_global_headers( | ||
| self, | ||
| test_agent: TestAgentAPI, | ||
| test_library: APMLibrary, | ||
| ) -> None: | ||
| headers = _request_headers(_trace_request(test_agent, test_library)) | ||
| _assert_routing_headers(headers) | ||
| assert all(name not in headers for name in ("header-one", "header-two")) | ||
|
|
||
| @pytest.mark.parametrize("library_env", [pytest.param({**BASE_ENVIRONMENT, VARIABLE: ""}, id="empty")]) | ||
| def test_empty_is_treated_as_unset( | ||
| self, | ||
| test_agent: TestAgentAPI, | ||
| test_library: APMLibrary, | ||
| ) -> None: | ||
| headers = _request_headers(_trace_request(test_agent, test_library)) | ||
| _assert_routing_headers(headers) | ||
| assert all(name not in headers for name in ("header-one", "header-two")) |
133 changes: 133 additions & 0 deletions
133
tests/parametric/otel_env_vars/test_otel_exporter_otlp_traces_protocol.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| from tests.parametric.conftest import APMLibrary | ||
| from utils import features, pytest, scenarios | ||
| from utils.docker_fixtures import TestAgentAPI | ||
| from utils.docker_fixtures._test_agent import AgentRequest | ||
|
|
||
|
|
||
| OTLP_TRACE_PATH = "/v1/traces" | ||
| ROUTING_HEADERS = "dd-protocol=otlp,dd-otlp-path=agent" | ||
| DEFAULT_PROTOCOL = "http/protobuf" | ||
|
|
||
| BASE_ENVIRONMENT = { | ||
| "DD_TRACE_AGENT_PROTOCOL_VERSION": None, | ||
| "DD_TRACE_ENABLED": None, | ||
| "DD_TRACE_OTEL_ENABLED": "true", | ||
| "OTEL_EXPORTER_OTLP_TRACES_HEADERS": ROUTING_HEADERS, | ||
| "OTEL_TRACES_EXPORTER": "otlp", | ||
| } | ||
|
|
||
| CONTENT_TYPES = { | ||
| "grpc": "application/grpc", | ||
| "http/protobuf": "application/x-protobuf", | ||
| "http/json": "application/json", | ||
| } | ||
|
|
||
| GRPC_PROTOCOL_VALUE = [ | ||
| pytest.param({**BASE_ENVIRONMENT, "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL": "grpc"}, "grpc", id="grpc"), | ||
| ] | ||
|
|
||
| HTTP_PROTOCOL_VALUES = [ | ||
| pytest.param( | ||
| {**BASE_ENVIRONMENT, "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL": "http/protobuf"}, | ||
| "http/protobuf", | ||
| id="http-protobuf", | ||
| ), | ||
| pytest.param( | ||
| {**BASE_ENVIRONMENT, "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL": "http/json"}, | ||
| "http/json", | ||
| id="http-json", | ||
| ), | ||
| ] | ||
|
|
||
| UNSET_VALUE = [pytest.param({**BASE_ENVIRONMENT}, DEFAULT_PROTOCOL, id="unset")] | ||
| EMPTY_VALUE = [ | ||
| pytest.param( | ||
| {**BASE_ENVIRONMENT, "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL": ""}, | ||
| DEFAULT_PROTOCOL, | ||
| id="empty", | ||
| ) | ||
| ] | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def _trace_export_endpoint( | ||
| library_env: dict[str, str], | ||
| test_agent: TestAgentAPI, | ||
| test_agent_otlp_http_port: int, | ||
| test_agent_otlp_grpc_port: int, | ||
| ) -> None: | ||
| protocol = library_env.get("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL") or DEFAULT_PROTOCOL | ||
| if protocol == "grpc": | ||
| library_env["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = ( | ||
| f"http://{test_agent.container_name}:{test_agent_otlp_grpc_port}" | ||
| ) | ||
| return | ||
|
|
||
| library_env["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = ( | ||
| f"http://{test_agent.container_name}:{test_agent_otlp_http_port}{OTLP_TRACE_PATH}" | ||
| ) | ||
|
|
||
|
|
||
| def _trace_request(test_agent: TestAgentAPI, test_library: APMLibrary) -> AgentRequest: | ||
| with test_library as library: | ||
| with library.dd_start_span(name="otel-otlp-traces-protocol"): | ||
| pass | ||
| library.dd_flush() | ||
|
|
||
| requests = [request for request in test_agent.requests() if request["url"].endswith(OTLP_TRACE_PATH)] | ||
| assert requests, f"Expected OTLP trace request, got {test_agent.requests()}" | ||
| return requests[0] | ||
|
|
||
|
|
||
| def _assert_protocol( | ||
| test_agent: TestAgentAPI, | ||
| test_library: APMLibrary, | ||
| expected_protocol: str, | ||
| ) -> None: | ||
| request = _trace_request(test_agent, test_library) | ||
| headers = {name.lower(): value for name, value in request["headers"].items()} | ||
| assert headers.get("content-type", "").startswith(CONTENT_TYPES[expected_protocol]) | ||
|
|
||
|
|
||
| @scenarios.parametric | ||
| @features.otel_exporter_otlp_traces_protocol | ||
| class Test_OTEL_EXPORTER_OTLP_TRACES_PROTOCOL: | ||
| @pytest.mark.parametrize(("library_env", "expected_protocol"), GRPC_PROTOCOL_VALUE) | ||
| def test_grpc_protocol_is_used_for_trace_export( | ||
| self, | ||
| test_agent: TestAgentAPI, | ||
| test_library: APMLibrary, | ||
| *, | ||
| expected_protocol: str, | ||
| ) -> None: | ||
| _assert_protocol(test_agent, test_library, expected_protocol) | ||
|
|
||
| @pytest.mark.parametrize(("library_env", "expected_protocol"), HTTP_PROTOCOL_VALUES) | ||
| def test_http_protocol_is_used_for_trace_export( | ||
| self, | ||
| test_agent: TestAgentAPI, | ||
| test_library: APMLibrary, | ||
| *, | ||
| expected_protocol: str, | ||
| ) -> None: | ||
| _assert_protocol(test_agent, test_library, expected_protocol) | ||
|
|
||
| @pytest.mark.parametrize(("library_env", "expected_protocol"), UNSET_VALUE) | ||
| def test_unset_uses_specification_default( | ||
| self, | ||
| test_agent: TestAgentAPI, | ||
| test_library: APMLibrary, | ||
| *, | ||
| expected_protocol: str, | ||
| ) -> None: | ||
| _assert_protocol(test_agent, test_library, expected_protocol) | ||
|
|
||
| @pytest.mark.parametrize(("library_env", "expected_protocol"), EMPTY_VALUE) | ||
| def test_empty_is_treated_as_unset( | ||
| self, | ||
| test_agent: TestAgentAPI, | ||
| test_library: APMLibrary, | ||
| *, | ||
| expected_protocol: str, | ||
| ) -> None: | ||
| _assert_protocol(test_agent, test_library, expected_protocol) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.