-
Notifications
You must be signed in to change notification settings - Fork 242
/
test_helper.rb
68 lines (57 loc) · 1.88 KB
/
test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true
# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0
if RUBY_ENGINE == 'ruby'
require 'simplecov'
SimpleCov.start
end
require 'opentelemetry-test-helpers'
require 'opentelemetry/exporter/zipkin'
require 'minitest/autorun'
require 'webmock/minitest'
OpenTelemetry.logger = Logger.new(File::NULL)
def create_span_data(status: nil, kind: nil, attributes: nil, total_recorded_attributes: 0, events: nil, total_recorded_events: 0, links: nil, total_recorded_links: 0, instrumentation_scope: OpenTelemetry::SDK::InstrumentationScope.new('vendorlib', '0.0.0'), trace_id: OpenTelemetry::Trace.generate_trace_id, trace_flags: OpenTelemetry::Trace::TraceFlags::DEFAULT, tracestate: nil)
OpenTelemetry::SDK::Trace::SpanData.new(
'',
kind,
status,
OpenTelemetry::Trace::INVALID_SPAN_ID,
total_recorded_attributes,
total_recorded_events,
total_recorded_links,
OpenTelemetry::TestHelpers.exportable_timestamp,
OpenTelemetry::TestHelpers.exportable_timestamp,
attributes,
links,
events,
nil,
instrumentation_scope,
OpenTelemetry::Trace.generate_span_id,
trace_id,
trace_flags,
tracestate
)
end
# Test helper for Zipkin Exporter
class InMemoryMetricsReporter
include OpenTelemetry::SDK::Trace::Export::MetricsReporter
attr_reader :counters, :records, :observes
def initialize
@counters = []
@records = []
@observes = []
end
def record_value(metric, value:, labels: {})
@records << { metric: metric, value: value, labels: labels }
end
def observe_value(metric, value:, labels: {})
@observes << { metric: metric, value: value, labels: labels }
end
def add_to_counter(metric, increment: 1, labels: {})
@counters << { metric: metric, value: increment, labels: labels }
end
def empty?
@counters.empty? && @records.empty? && @observes.empty?
end
end