-
Notifications
You must be signed in to change notification settings - Fork 22
Implement Unit Test for Tracer Configurer Module #38
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
90120d9
completed but have issue
XinRanZhAWS 1bbe3ef
Functional complete
4c9f74f
Checksytle fix
5d1c5a0
Implement sampler test
442fea9
test whats wrong with checks
c14a153
test whats wrong with checks
d1cf096
test whats wrong with checks
b90abc1
test
4da1705
Fix an issue in conflict global tracer_provider
cc2f729
checkstyle fix
c7efd49
Fix based on Comment
d4a8a12
Fix based on Comment
6322448
Checkstyle fix
46999fb
Checkstyle fix
744fd84
Checkstyle fix
3592f9c
Fix based on comment
f45fa99
chkstyle
3a2f376
chkstyle fix
fb62cad
Fix comment
thpierce 203f425
Merge branch 'main' into unittest_tracer_configurer
XinRanZhAWS 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
54 changes: 54 additions & 0 deletions
54
aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_tracer_configurer.py
thpierce marked this conversation as resolved.
Show resolved
Hide resolved
|
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,54 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import os | ||
import time | ||
from unittest import TestCase | ||
|
||
from amazon.opentelemetry.distro.aws_opentelemetry_configurator import AwsOpenTelemetryConfigurator | ||
from amazon.opentelemetry.distro.aws_opentelemetry_distro import AwsOpenTelemetryDistro | ||
from opentelemetry.environment_variables import OTEL_LOGS_EXPORTER, OTEL_METRICS_EXPORTER, OTEL_TRACES_EXPORTER | ||
from opentelemetry.sdk.environment_variables import OTEL_TRACES_SAMPLER, OTEL_TRACES_SAMPLER_ARG | ||
from opentelemetry.sdk.trace import Span, Tracer, TracerProvider | ||
from opentelemetry.trace import get_tracer_provider | ||
|
||
|
||
# This class setup Tracer Provider Globally, which can only set once | ||
# if there is another setup for tracer provider, may cause issue | ||
class TestAwsTracerConfigurer(TestCase): | ||
thpierce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@classmethod | ||
def setUpClass(cls): | ||
os.environ.setdefault(OTEL_TRACES_EXPORTER, "none") | ||
os.environ.setdefault(OTEL_METRICS_EXPORTER, "none") | ||
os.environ.setdefault(OTEL_LOGS_EXPORTER, "none") | ||
os.environ.setdefault(OTEL_TRACES_SAMPLER, "traceidratio") | ||
os.environ.setdefault(OTEL_TRACES_SAMPLER_ARG, "0.01") | ||
aws_open_telemetry_distro: AwsOpenTelemetryDistro = AwsOpenTelemetryDistro() | ||
aws_open_telemetry_distro.configure() | ||
aws_otel_configurator: AwsOpenTelemetryConfigurator = AwsOpenTelemetryConfigurator() | ||
aws_otel_configurator.configure() | ||
cls.tracer_provider: TracerProvider = get_tracer_provider() | ||
|
||
# The probability of this passing once without correct IDs is low, 20 times is inconceivable. | ||
def test_provide_generate_xray_ids(self): | ||
for _ in range(20): | ||
tracer: Tracer = self.tracer_provider.get_tracer("test") | ||
start_time_sec: int = int(time.time()) | ||
span: Span = tracer.start_span("test") | ||
trace_id: int = span.get_span_context().trace_id | ||
trace_id_4_byte_hex: str = hex(trace_id)[2:10] | ||
trace_id_4_byte_int: int = int(trace_id_4_byte_hex, 16) | ||
self.assertGreaterEqual(trace_id_4_byte_int, start_time_sec) | ||
|
||
# Sanity check that the trace ID ratio sampler works fine with the x-ray generator. | ||
def test_trace_id_ratio_sampler(self): | ||
for _ in range(20): | ||
num_spans: int = 100000 | ||
num_sampled: int = 0 | ||
tracer: Tracer = self.tracer_provider.get_tracer("test") | ||
for _ in range(num_spans): | ||
span: Span = tracer.start_span("test") | ||
if span.get_span_context().trace_flags.sampled: | ||
num_sampled += 1 | ||
span.end() | ||
# Configured for 1%, confirm there are at most 5% to account for randomness and reduce test flakiness. | ||
self.assertGreater(0.05, num_sampled / num_spans) |
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.