-
Notifications
You must be signed in to change notification settings - Fork 13
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
[opentelemetry] Add OTLP intake E2E system tests #976
Merged
Merged
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f66b76a
[opentelemetry] Add OTLP intake E2E system tests
songy23 50a251c
Refactor OTel system tests
songy23 4843837
Merge branch 'main' into yang.song/otlp-intake-test
songy23 ec52e30
Format
songy23 558e7d3
Merge branch 'main' into yang.song/otlp-intake-test
songy23 9c94045
Fix review comments
songy23 8ee4333
Remove unused deps
songy23 75e47f3
Merge branch 'main' into yang.song/otlp-intake-test
cbeauchesne 230216c
Merge main
cbeauchesne 80d089f
introduce open telemetry interface
cbeauchesne 62ae0b3
Minor fixes
cbeauchesne 3aec32d
Use correct proxy in exporter
songy23 5810006
More fixes on otel e2e test
songy23 1b79c07
Merge branch 'main' into yang.song/otlp-intake-test
songy23 e298580
Fix a merge conflict
songy23 90e665a
Add otel in CI
cbeauchesne ec918cc
Fix build failure in run.sh
songy23 c143cd4
Fix CI failure
songy23 d42fdbd
Fix test-the-tests-open-telemetry CI config
songy23 9dfbd40
Merge branch 'main' into yang.song/otlp-intake-test
cbeauchesne 04f1547
Remove unused func
songy23 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 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 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 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 |
---|---|---|
|
@@ -25,4 +25,6 @@ rfc3339-validator==0.1.4 | |
matplotlib | ||
|
||
docker==6.0.0 | ||
|
||
opentelemetry-proto==1.17.0 | ||
paramiko==3.1.0 |
This file contains 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,77 @@ | ||
# Util functions to validate JSON trace data from OTel system tests | ||
|
||
import json | ||
|
||
|
||
def validate_trace(traces: list, use_128_bits_trace_id: bool): | ||
server_span = None | ||
message_span = None | ||
for trace in traces: | ||
spans = trace["spans"] | ||
assert len(spans) == 1 | ||
for item in spans.items(): | ||
span = item[1] | ||
validate_common_tags(span, use_128_bits_trace_id) | ||
if span["type"] == "web": | ||
server_span = span | ||
elif span["type"] == "custom": | ||
message_span = span | ||
else: | ||
raise Exception("Unexpected span ", span) | ||
validate_server_span(server_span) | ||
validate_message_span(message_span) | ||
validate_span_link(server_span, message_span) | ||
|
||
|
||
def validate_common_tags(span: dict, use_128_bits_trace_id: bool): | ||
expected_tags = { | ||
"parent_id": "0", | ||
"env": "system-tests", | ||
"service": "otel-system-tests-spring-boot", | ||
"ingestion_reason": "otel", | ||
} | ||
expected_meta = { | ||
"env": "system-tests", | ||
"deployment.environment": "system-tests", | ||
"_dd.ingestion_reason": "otel", | ||
"otel.status_code": "Unset", | ||
"otel.user_agent": "OTel-OTLP-Exporter-Java/1.23.1", | ||
"otel.library.name": "com.datadoghq.springbootnative", | ||
} | ||
assert expected_tags.items() <= span.items() | ||
assert expected_meta.items() <= span["meta"].items() | ||
validate_trace_id(span, use_128_bits_trace_id) | ||
|
||
|
||
def validate_trace_id(span: dict, use_128_bits_trace_id: bool): | ||
dd_trace_id = int(span["trace_id"], base=10) | ||
otel_trace_id = int(span["meta"]["otel.trace_id"], base=16) | ||
if use_128_bits_trace_id: | ||
assert dd_trace_id == otel_trace_id | ||
else: | ||
trace_id_bytes = otel_trace_id.to_bytes(16, "big") | ||
assert dd_trace_id == int.from_bytes(trace_id_bytes[8:], "big") | ||
|
||
|
||
def validate_server_span(span: dict): | ||
expected_tags = {"name": "WebController.home", "resource": "GET /"} | ||
expected_meta = {"http.route": "/", "http.method": "GET"} | ||
assert expected_tags.items() <= span.items() | ||
assert expected_meta.items() <= span["meta"].items() | ||
|
||
|
||
def validate_message_span(span: dict): | ||
expected_tags = {"name": "WebController.home.publish", "resource": "publish"} | ||
expected_meta = {"messaging.operation": "publish", "messaging.system": "rabbitmq"} | ||
assert expected_tags.items() <= span.items() | ||
assert expected_meta.items() <= span["meta"].items() | ||
|
||
|
||
def validate_span_link(server_span: dict, message_span: dict): | ||
span_links = json.loads(server_span["meta"]["_dd.span_links"]) | ||
assert len(span_links) == 1 | ||
span_link = span_links[0] | ||
assert span_link["trace_id"] == message_span["meta"]["otel.trace_id"] | ||
span_id_hex = f'{int(message_span["span_id"]):x}' # span_id is an int in span but a hex in span_links | ||
assert span_link["span_id"] == span_id_hex | ||
assert span_link["attributes"] == {"messaging.operation": "publish"} |
This file contains 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,25 @@ | ||
from _validator import validate_trace | ||
from utils import context, weblog, interfaces, scenarios, irrelevant | ||
|
||
|
||
@scenarios.otel_tracing_e2e | ||
@irrelevant(context.library != "open_telemetry") | ||
class Test_OTel_E2E: | ||
def setup_main(self): | ||
self.use_128_bits_trace_id = False | ||
self.r = weblog.get(path="/") | ||
|
||
def test_main(self): | ||
otel_trace_ids = set(interfaces.open_telemetry.get_otel_trace_id(request=self.r)) | ||
assert len(otel_trace_ids) == 2 | ||
dd_trace_ids = [self._get_dd_trace_id(otel_trace_id) for otel_trace_id in otel_trace_ids] | ||
traces = [ | ||
interfaces.backend.assert_otlp_trace_exist(request=self.r, dd_trace_id=dd_trace_id) | ||
for dd_trace_id in dd_trace_ids | ||
] | ||
validate_trace(traces, self.use_128_bits_trace_id) | ||
|
||
def _get_dd_trace_id(self, otel_trace_id=bytes) -> int: | ||
if self.use_128_bits_trace_id: | ||
return int.from_bytes(otel_trace_id, "big") | ||
return int.from_bytes(otel_trace_id[8:], "big") |
This file contains 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 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
29 changes: 29 additions & 0 deletions
29
utils/build/docker/java_otel/spring-boot-native.Dockerfile
This file contains 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,29 @@ | ||
FROM openjdk:17-buster | ||
|
||
# Install required bsdtar | ||
RUN apt-get update && \ | ||
apt-get install -y libarchive-tools | ||
|
||
|
||
# Install maven | ||
RUN curl https://archive.apache.org/dist/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz --output /opt/maven.tar.gz && \ | ||
tar xzvf /opt/maven.tar.gz --directory /opt && \ | ||
rm /opt/maven.tar.gz | ||
|
||
WORKDIR /app | ||
|
||
# Copy application sources and cache dependencies | ||
COPY ./utils/build/docker/java_otel/spring-boot-native/pom.xml . | ||
COPY ./utils/build/docker/java_otel/spring-boot-native/src ./src | ||
|
||
# Compile application | ||
RUN /opt/apache-maven-3.8.6/bin/mvn clean package | ||
|
||
# Set up required args | ||
RUN echo "1.23.1" > SYSTEM_TESTS_LIBRARY_VERSION | ||
RUN echo "1.0.0" > SYSTEM_TESTS_LIBDDWAF_VERSION | ||
RUN echo "1.0.0" > SYSTEM_TESTS_APPSEC_EVENT_RULES_VERSION | ||
|
||
RUN echo "#!/bin/bash\njava -jar target/myproject-3.0.0-SNAPSHOT.jar --server.port=7777" > app.sh | ||
RUN chmod +x app.sh | ||
CMD [ "./app.sh" ] |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need these, since they are already set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually needed - we set dd api key and dd site for Agent containers but not Weblog containers.