instana 1.217.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +101 -225
  3. data/.tekton/.currency/scripts/generate_report.py +194 -22
  4. data/.tekton/pipeline.yaml +65 -152
  5. data/.tekton/prepuller-restart-service-account.yaml +31 -0
  6. data/.tekton/ruby-tracer-prepuller-cronjob.yaml +20 -0
  7. data/.tekton/ruby-tracer-prepuller.yaml +27 -26
  8. data/.tekton/task.yaml +31 -27
  9. data/Gemfile +5 -0
  10. data/README.md +2 -1
  11. data/Rakefile +1 -1
  12. data/examples/otel.rb +98 -0
  13. data/examples/tracing.rb +1 -0
  14. data/gemfiles/rails_61.gemfile +1 -0
  15. data/gemfiles/rails_70.gemfile +1 -0
  16. data/instana.gemspec +5 -0
  17. data/lib/instana/base.rb +4 -2
  18. data/lib/instana/instrumentation/action_cable.rb +8 -4
  19. data/lib/instana/instrumentation/action_controller.rb +2 -4
  20. data/lib/instana/instrumentation/action_mailer.rb +1 -1
  21. data/lib/instana/instrumentation/action_view.rb +4 -4
  22. data/lib/instana/instrumentation/active_job.rb +26 -13
  23. data/lib/instana/instrumentation/active_record.rb +1 -1
  24. data/lib/instana/instrumentation/aws_sdk_dynamodb.rb +1 -1
  25. data/lib/instana/instrumentation/aws_sdk_lambda.rb +1 -1
  26. data/lib/instana/instrumentation/aws_sdk_s3.rb +1 -1
  27. data/lib/instana/instrumentation/aws_sdk_sns.rb +1 -1
  28. data/lib/instana/instrumentation/aws_sdk_sqs.rb +1 -1
  29. data/lib/instana/instrumentation/dalli.rb +1 -1
  30. data/lib/instana/instrumentation/excon.rb +2 -2
  31. data/lib/instana/instrumentation/graphql.rb +3 -3
  32. data/lib/instana/instrumentation/grpc.rb +14 -13
  33. data/lib/instana/instrumentation/mongo.rb +3 -3
  34. data/lib/instana/instrumentation/net-http.rb +5 -4
  35. data/lib/instana/instrumentation/rack.rb +36 -4
  36. data/lib/instana/instrumentation/redis.rb +1 -1
  37. data/lib/instana/instrumentation/resque.rb +10 -8
  38. data/lib/instana/instrumentation/rest-client.rb +4 -4
  39. data/lib/instana/instrumentation/sequel.rb +3 -3
  40. data/lib/instana/instrumentation/shoryuken.rb +4 -1
  41. data/lib/instana/instrumentation/sidekiq-client.rb +21 -19
  42. data/lib/instana/instrumentation/sidekiq-worker.rb +22 -21
  43. data/lib/instana/instrumented_logger.rb +1 -1
  44. data/lib/instana/samplers/result.rb +32 -0
  45. data/lib/instana/samplers/samplers.rb +76 -0
  46. data/lib/instana/serverless.rb +4 -2
  47. data/lib/instana/setup.rb +4 -5
  48. data/lib/instana/trace/export.rb +36 -0
  49. data/lib/instana/{tracing → trace}/processor.rb +19 -15
  50. data/lib/instana/trace/span.rb +532 -0
  51. data/lib/instana/{tracing → trace}/span_context.rb +17 -8
  52. data/lib/instana/trace/span_kind.rb +51 -0
  53. data/lib/instana/trace/span_limits.rb +63 -0
  54. data/lib/instana/{tracer.rb → trace/tracer.rb} +106 -54
  55. data/lib/instana/trace/tracer_provider.rb +198 -0
  56. data/lib/instana/trace.rb +74 -0
  57. data/lib/instana/util.rb +11 -0
  58. data/lib/instana/version.rb +1 -1
  59. data/test/frameworks/sinatra_test.rb +2 -1
  60. data/test/instrumentation/aws_test.rb +7 -7
  61. data/test/instrumentation/dalli_test.rb +8 -8
  62. data/test/instrumentation/excon_test.rb +3 -3
  63. data/test/instrumentation/graphql_test.rb +4 -4
  64. data/test/instrumentation/grpc_test.rb +8 -8
  65. data/test/instrumentation/mongo_test.rb +1 -1
  66. data/test/instrumentation/net_http_test.rb +6 -6
  67. data/test/instrumentation/rails_action_cable_test.rb +2 -2
  68. data/test/instrumentation/rails_action_mailer_test.rb +1 -1
  69. data/test/instrumentation/rails_active_job_test.rb +1 -1
  70. data/test/instrumentation/rails_active_record_database_missing_test.rb +2 -3
  71. data/test/instrumentation/rails_active_record_test.rb +8 -7
  72. data/test/instrumentation/redis_test.rb +7 -7
  73. data/test/instrumentation/resque_test.rb +5 -5
  74. data/test/instrumentation/rest_client_test.rb +1 -2
  75. data/test/instrumentation/sequel_test.rb +12 -6
  76. data/test/instrumentation/sidekiq-client_test.rb +2 -2
  77. data/test/instrumentation/sidekiq-worker_test.rb +2 -2
  78. data/test/{tracing → trace}/custom_test.rb +32 -25
  79. data/test/{tracing → trace}/id_management_test.rb +0 -2
  80. data/test/{tracing → trace}/instrumented_logger_test.rb +1 -1
  81. data/test/{tracing → trace}/processor_test.rb +6 -6
  82. data/test/{tracing → trace}/span_context_test.rb +3 -3
  83. data/test/{tracing → trace}/span_test.rb +7 -7
  84. data/test/{tracing → trace}/tracer_async_test.rb +43 -30
  85. data/test/trace/tracer_provider_test.rb +148 -0
  86. data/test/{tracing → trace}/tracer_test.rb +48 -37
  87. metadata +105 -32
  88. data/examples/opentracing.rb +0 -35
  89. data/lib/instana/open_tracing/carrier.rb +0 -7
  90. data/lib/instana/open_tracing/instana_tracer.rb +0 -99
  91. data/lib/instana/tracing/span.rb +0 -431
  92. data/lib/opentracing.rb +0 -32
  93. data/test/tracing/opentracing_test.rb +0 -382
@@ -0,0 +1,76 @@
1
+ # (c) Copyright IBM Corp. 2025
2
+ require 'instana/samplers/result'
3
+ module Instana
4
+ module Trace
5
+ # The Samplers module contains the sampling logic for OpenTelemetry. The
6
+ # reference implementation provides a {TraceIdRatioBased}, {ALWAYS_ON},
7
+ # {ALWAYS_OFF}, and {ParentBased}.
8
+ #
9
+ # Custom samplers can be provided by SDK users. The required interface is:
10
+ #
11
+ # should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) -> Result
12
+ # description -> String
13
+ #
14
+ # Where:
15
+ #
16
+ # @param [String] trace_id The trace_id of the {Span} to be created.
17
+ # @param [OpenTelemetry::Context] parent_context The
18
+ # {OpenTelemetry::Context} with a parent {Span}. The {Span}'s
19
+ # {OpenTelemetry::Trace::SpanContext} may be invalid to indicate a
20
+ # root span.
21
+ # @param [Enumerable<Link>] links A collection of links to be associated
22
+ # with the {Span} to be created. Can be nil.
23
+ # @param [String] name Name of the {Span} to be created.
24
+ # @param [Symbol] kind The {OpenTelemetry::Trace::SpanKind} of the {Span}
25
+ # to be created. Can be nil.
26
+ # @param [Hash<String, Object>] attributes Attributes to be attached
27
+ # to the {Span} to be created. Can be nil.
28
+ # @return [Result] The sampling result.
29
+ module Samplers
30
+ # Returns a {Result} with {Decision::RECORD_AND_SAMPLE}.
31
+ ALWAYS_ON = false
32
+ # # Returns a {Result} with {Decision::DROP}.
33
+ ALWAYS_OFF = true
34
+
35
+ # Returns a new sampler. It delegates to samplers according to the following rules:
36
+ #
37
+ # | Parent | parent.remote? | parent.trace_flags.sampled? | Invoke sampler |
38
+ # |--|--|--|--|
39
+ # | absent | n/a | n/a | root |
40
+ # | present | true | true | remote_parent_sampled |
41
+ # | present | true | false | remote_parent_not_sampled |
42
+ # | present | false | true | local_parent_sampled |
43
+ # | present | false | false | local_parent_not_sampled |
44
+ #
45
+ # @param [Sampler] root The sampler to which the sampling
46
+ # decision is delegated for spans with no parent (root spans).
47
+ # @param [optional Sampler] remote_parent_sampled The sampler to which the sampling
48
+ # decision is delegated for remote parent sampled spans. Defaults to ALWAYS_ON.
49
+ # @param [optional Sampler] remote_parent_not_sampled The sampler to which the sampling
50
+ # decision is delegated for remote parent not sampled spans. Defaults to ALWAYS_OFF.
51
+ # @param [optional Sampler] local_parent_sampled The sampler to which the sampling
52
+ # decision is delegated for local parent sampled spans. Defaults to ALWAYS_ON.
53
+ # @param [optional Sampler] local_parent_not_sampled The sampler to which the sampling
54
+ # decision is delegated for local parent not sampld spans. Defaults to ALWAYS_OFF.
55
+ def self.parent_based(_)
56
+ self
57
+ end
58
+
59
+ # Returns a new sampler. The ratio describes the proportion of the trace ID
60
+ # space that is sampled.
61
+ #
62
+ # @param [Numeric] ratio The desired sampling ratio.
63
+ # Must be within [0.0, 1.0].
64
+ # @raise [ArgumentError] if ratio is out of range
65
+ def self.trace_id_ratio_based(_)
66
+ self
67
+ end
68
+
69
+ def self.should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) # rubocop:disable Metrics/ParameterLists, Lint/UnusedMethodArgument:
70
+ parent_span_context = OpenTelemetry::Trace.current_span(parent_context).context
71
+ tracestate = parent_span_context&.tracestate
72
+ Result.new(decision: :__record_only__, tracestate: tracestate)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -42,8 +42,10 @@ module Instana
42
42
  else
43
43
  tags[:lambda] = tags[:lambda].merge(event_tags)
44
44
  end
45
-
46
- @tracer.start_or_continue_trace(:'aws.lambda.entry', tags, span_context, &block)
45
+ Trace.with_span(OpenTelemetry::Trace.non_recording_span(::Instana::SpanContext.new(trace_id: span_context[:trace_id], span_id: span_context[:span_id],
46
+ level: span_context[:level]))) do
47
+ @tracer.in_span(:'aws.lambda.entry', attributes: tags, &block)
48
+ end
47
49
  ensure
48
50
  begin
49
51
  @agent.send_bundle
data/lib/instana/setup.rb CHANGED
@@ -11,8 +11,8 @@ require 'instana/instrumented_logger'
11
11
  require "instana/base"
12
12
  require "instana/config"
13
13
  require "instana/secrets"
14
- require "instana/tracer"
15
- require "instana/tracing/processor"
14
+ require "instana/trace/tracer"
15
+ require "instana/trace/processor"
16
16
 
17
17
  require 'instana/serverless'
18
18
 
@@ -39,13 +39,12 @@ require 'instana/backend/host_agent_reporting_observer'
39
39
  require 'instana/backend/host_agent'
40
40
  require 'instana/backend/serverless_agent'
41
41
  require 'instana/backend/agent'
42
+ require 'instana/trace'
43
+ require 'instana/trace/tracer_provider'
42
44
 
43
45
  ::Instana.setup
44
46
  ::Instana.agent.setup
45
47
 
46
- # Require supported OpenTracing interfaces
47
- require "opentracing"
48
-
49
48
  # The Instana agent is now setup. The only remaining
50
49
  # task for a complete boot is to call
51
50
  # `Instana.agent.start` in the thread of your choice.
@@ -0,0 +1,36 @@
1
+ # (c) Copyright IBM Corp. 2025
2
+
3
+ module Instana
4
+ module Trace
5
+ # The Export module contains the built-in exporters and span processors for the OpenTelemetry
6
+ # reference implementation.
7
+ module Export
8
+ # Raised when an export fails; spans are available via :spans accessor
9
+ class ExportError < OpenTelemetry::Error
10
+ # Returns the {Span} array for this exception
11
+ #
12
+ # @return [Array<OpenTelemetry::SDK::Trace::Span>]
13
+ attr_reader :spans
14
+
15
+ # @param [Array<OpenTelemetry::SDK::Trace::Span>] spans the array of spans that failed to export
16
+ def initialize(spans)
17
+ super("Unable to export #{spans.size} spans")
18
+ @spans = spans
19
+ end
20
+ end
21
+
22
+ # Result codes for the SpanExporter#export method and the SpanProcessor#force_flush and SpanProcessor#shutdown methods.
23
+
24
+ # The operation finished successfully.
25
+ SUCCESS = 0
26
+
27
+ # The operation finished with an error.
28
+ FAILURE = 1
29
+
30
+ # Additional result code for the SpanProcessor#force_flush and SpanProcessor#shutdown methods.
31
+
32
+ # The operation timed out.
33
+ TIMEOUT = 2
34
+ end
35
+ end
36
+ end
@@ -1,7 +1,6 @@
1
1
  # (c) Copyright IBM Corp. 2021
2
2
  # (c) Copyright Instana Inc. 2016
3
3
 
4
- require 'thread'
5
4
  require 'forwardable'
6
5
 
7
6
  module Instana
@@ -25,10 +24,13 @@ module Instana
25
24
  @spans_closed = Concurrent::AtomicFixnum.new(0)
26
25
  end
27
26
 
28
- # Adds a span to the span queue
29
- #
30
- # @param [Trace] - the trace to be added to the queue
31
- def add_span(span)
27
+ # Note that we've started a new span. Used to
28
+ # generate monitoring metrics.
29
+ def on_start(_)
30
+ @spans_opened.increment
31
+ end
32
+
33
+ def on_finish(span)
32
34
  # :nocov:
33
35
  if @pid != Process.pid
34
36
  @logger.info("Proces `#{@pid}` has forked into #{Process.pid}. Running post fork hook.")
@@ -41,12 +43,6 @@ module Instana
41
43
  @queue.push(span)
42
44
  end
43
45
 
44
- # Note that we've started a new span. Used to
45
- # generate monitoring metrics.
46
- def start_span(_)
47
- @spans_opened.increment
48
- end
49
-
50
46
  # Clears and retrieves metrics associated with span creation and submission
51
47
  def span_metrics
52
48
  response = {
@@ -94,9 +90,13 @@ module Instana
94
90
  return [] if @queue.empty?
95
91
 
96
92
  spans = []
97
- until @queue.empty? do
93
+ until @queue.empty?
98
94
  # Non-blocking pop; ignore exception
99
- span = @queue.pop(true) rescue nil
95
+ span = begin
96
+ @queue.pop(true)
97
+ rescue
98
+ nil
99
+ end
100
100
  spans << span.raw if span.is_a?(Span) && span.context.level == 1
101
101
  end
102
102
 
@@ -110,9 +110,13 @@ module Instana
110
110
  @spans_opened.value = 0
111
111
  @spans_closed.value = 0
112
112
 
113
- until @queue.empty? do
113
+ until @queue.empty?
114
114
  # Non-blocking pop; ignore exception
115
- @queue.pop(true) rescue nil
115
+ begin
116
+ @queue.pop(true)
117
+ rescue
118
+ nil
119
+ end
116
120
  end
117
121
  end
118
122
  end