Skip to content

Commit 6bfe214

Browse files
committed
cleanup tests, logs, and semconv
1 parent a7dc5ca commit 6bfe214

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

sampler/xray/lib/opentelemetry/sampler/xray/aws_xray_remote_sampler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def retrieve_and_update_sampling_rules
122122
OpenTelemetry.logger.error('GetSamplingRules Response is falsy')
123123
end
124124
rescue StandardError => e
125-
OpenTelemetry.logger.error("Error occurred when retrieving or updating Sampling Rules: #{e}")
125+
OpenTelemetry.handle_error(exception: e, message: 'Error occurred when retrieving or updating Sampling Rules')
126126
end
127127

128128
def update_sampling_rules(response_object)

sampler/xray/lib/opentelemetry/sampler/xray/aws_xray_sampling_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def parse_endpoint(endpoint)
5151
host, port = endpoint.split(':')
5252
[host, port.to_i]
5353
rescue StandardError => e
54-
OpenTelemetry.logger.error("Invalid endpoint: #{endpoint}")
54+
OpenTelemetry.handle_error(exception: e, message: "Invalid endpoint: #{endpoint}")
5555
raise e
5656
end
5757
end

sampler/xray/lib/opentelemetry/sampler/xray/sampling_rule_applier.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class SamplingRuleApplier
2020
attr_reader :sampling_rule
2121

2222
MAX_DATE_TIME_SECONDS = Time.at(8_640_000_000_000)
23+
SEMCONV = OpenTelemetry::SemanticConventions
2324

2425
def initialize(sampling_rule, statistics = OpenTelemetry::Sampler::XRay::Statistics.new, target = nil)
2526
@sampling_rule = sampling_rule
@@ -38,10 +39,10 @@ def matches?(attributes, resource)
3839
http_host = nil
3940

4041
unless attributes.nil?
41-
http_target = attributes[OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET]
42-
http_url = attributes[OpenTelemetry::SemanticConventions::Trace::HTTP_URL]
43-
http_method = attributes[OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD]
44-
http_host = attributes[OpenTelemetry::SemanticConventions::Trace::HTTP_HOST]
42+
http_target = attributes[SEMCONV::Trace::HTTP_TARGET]
43+
http_url = attributes[SEMCONV::Trace::HTTP_URL]
44+
http_method = attributes[SEMCONV::Trace::HTTP_METHOD]
45+
http_host = attributes[SEMCONV::Trace::HTTP_HOST]
4546
end
4647

4748
service_type = nil
@@ -50,8 +51,8 @@ def matches?(attributes, resource)
5051
resource_hash = resource.attribute_enumerator.to_h
5152

5253
if resource
53-
service_name = resource_hash[OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME] || ''
54-
cloud_platform = resource_hash[OpenTelemetry::SemanticConventions::Resource::CLOUD_PLATFORM]
54+
service_name = resource_hash[SEMCONV::Resource::SERVICE_NAME] || ''
55+
cloud_platform = resource_hash[SEMCONV::Resource::CLOUD_PLATFORM]
5556
service_type = OpenTelemetry::Sampler::XRay::Utils::CLOUD_PLATFORM_MAPPING[cloud_platform] if cloud_platform.is_a?(String)
5657
resource_arn = get_arn(resource, attributes)
5758
end
@@ -99,11 +100,11 @@ def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:
99100

100101
def get_arn(resource, attributes)
101102
resource_hash = resource.attribute_enumerator.to_h
102-
arn = resource_hash[OpenTelemetry::SemanticConventions::Resource::AWS_ECS_CONTAINER_ARN] ||
103-
resource_hash[OpenTelemetry::SemanticConventions::Resource::AWS_ECS_CLUSTER_ARN] ||
104-
resource_hash[OpenTelemetry::SemanticConventions::Resource::AWS_EKS_CLUSTER_ARN]
103+
arn = resource_hash[SEMCONV::Resource::AWS_ECS_CONTAINER_ARN] ||
104+
resource_hash[SEMCONV::Resource::AWS_ECS_CLUSTER_ARN] ||
105+
resource_hash[SEMCONV::Resource::AWS_EKS_CLUSTER_ARN]
105106

106-
arn = attributes[OpenTelemetry::SemanticConventions::Trace::AWS_LAMBDA_INVOKED_ARN] || resource_hash[OpenTelemetry::SemanticConventions::Resource::FAAS_ID] if arn.nil?
107+
arn = attributes[SEMCONV::Trace::AWS_LAMBDA_INVOKED_ARN] || resource_hash[SEMCONV::Resource::FAAS_ID] if arn.nil?
107108
arn
108109
end
109110
end

sampler/xray/test/aws_xray_remote_sampler_test.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
DATA_DIR_SAMPLING_RULES = File.join(__dir__, 'data/test-remote-sampler_sampling-rules-response-sample.json')
1010
DATA_DIR_SAMPLING_TARGETS = File.join(__dir__, 'data/test-remote-sampler_sampling-targets-response-sample.json')
1111
TEST_URL = 'localhost:2000'
12+
SEMCONV = OpenTelemetry::SemanticConventions
1213

1314
describe OpenTelemetry::Sampler::XRay::AWSXRayRemoteSampler do
1415
it 'creates remote sampler with empty resource' do
@@ -33,8 +34,8 @@
3334
.to_return(status: 200, body: File.read(DATA_DIR_SAMPLING_TARGETS))
3435

3536
resource = OpenTelemetry::SDK::Resources::Resource.create(
36-
OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME => 'test-service-name',
37-
OpenTelemetry::SemanticConventions::Resource::CLOUD_PLATFORM => 'test-cloud-platform'
37+
SEMCONV::Resource::SERVICE_NAME => 'test-service-name',
38+
SEMCONV::Resource::CLOUD_PLATFORM => 'test-cloud-platform'
3839
)
3940
sampler = OpenTelemetry::Sampler::XRay::InternalAWSXRayRemoteSampler.new(resource: resource)
4041

@@ -53,8 +54,8 @@
5354
.to_return(status: 200, body: File.read(DATA_DIR_SAMPLING_TARGETS))
5455

5556
resource = OpenTelemetry::SDK::Resources::Resource.create(
56-
OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME => 'test-service-name',
57-
OpenTelemetry::SemanticConventions::Resource::CLOUD_PLATFORM => 'test-cloud-platform'
57+
SEMCONV::Resource::SERVICE_NAME => 'test-service-name',
58+
SEMCONV::Resource::CLOUD_PLATFORM => 'test-cloud-platform'
5859
)
5960
sampler = OpenTelemetry::Sampler::XRay::InternalAWSXRayRemoteSampler.new(
6061
resource: resource,
@@ -78,14 +79,13 @@
7879
.to_return(status: 200, body: File.read(DATA_DIR_SAMPLING_TARGETS))
7980

8081
resource = OpenTelemetry::SDK::Resources::Resource.create(
81-
OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME => 'test-service-name',
82-
OpenTelemetry::SemanticConventions::Resource::CLOUD_PLATFORM => 'test-cloud-platform'
82+
SEMCONV::Resource::SERVICE_NAME => 'test-service-name',
83+
SEMCONV::Resource::CLOUD_PLATFORM => 'test-cloud-platform'
8384
)
8485
rs = OpenTelemetry::Sampler::XRay::AWSXRayRemoteSampler.new(resource: resource)
8586

8687
attributes = { 'abc' => '1234' }
8788

88-
sleep(1.0)
8989
test_rule_applier = rs.instance_variable_get(:@root).instance_variable_get(:@root).instance_variable_get(:@rule_cache).instance_variable_get(:@rule_appliers)[0]
9090
assert_equal 'test', test_rule_applier.instance_variable_get(:@sampling_rule).instance_variable_get(:@rule_name)
9191
assert_equal OpenTelemetry::SDK::Trace::Samplers::Decision::DROP,

0 commit comments

Comments
 (0)