opentelemetry-processor-baggage 0.1.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1509e0dd86e9b4fcc4f84bc6e73c60867d9bc6df48d19c38fe3dd64df4445de0
4
- data.tar.gz: f29cb30b4945cf44f20a5ec9bb5e5ab61a9aacdd205485d8cabd64359b09b5e4
3
+ metadata.gz: d1ac725f4e0830cd6d82071c462e0d35866f079bc91fb9ce21352577661cf80a
4
+ data.tar.gz: 0c17a589c16515fb31b05d8a7c9024f91d5183ba157a77f15c5e52a742c6a2b9
5
5
  SHA512:
6
- metadata.gz: 2ce85503cd0be5803f9bc0ed9368653491f2b27e236876f9339c2ab6be83ab780536f44fdc0407b5d7f2ca916b5668983ac04ee63af8b71f03f8ee8de5c7118d
7
- data.tar.gz: 41474ef39a46c0e33402c6c8b89698071520814e8470a9813b95ed49551b0503c9b815d76caa3c07d03f3d358d2afc7602b83fa1a7ac9ada093fa82fd0d55dd3
6
+ metadata.gz: db1b6694173e3f07d91d0bed8e2f1623ffddd93d506e45797ab4542e76d9711213dad23690abfe910feab4afd6445f0ea9ac93cd88cc14f44ae3c3d21f52340b
7
+ data.tar.gz: 9516a23fd287ce645c2da4aa557e7514b70568254f1c2ccd995523f7c01f76348d7623fac6bd2ddfa279ba24a867a85b4590a6e9f988607e340c870d37bf6792
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Release History: opentelemetry-processor-baggage
2
2
 
3
+ ### v0.2.1 / 2024-11-26
4
+
5
+ * (No significant changes)
6
+
7
+ ### v0.2.0 / 2024-06-18
8
+
9
+ * BREAKING CHANGE: Add baggage key predicate func to baggage span processor
10
+
11
+ * ADDED: Add baggage key predicate func to baggage span processor
12
+
3
13
  ### v0.1.0 / 2024-04-18
4
14
 
5
15
  * Initial release.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This is an OpenTelemetry [span processor](https://opentelemetry.io/docs/specs/otel/trace/sdk/#span-processor) that reads key/values stored in [Baggage](https://opentelemetry.io/docs/specs/otel/baggage/api/) in the starting span's parent context and adds them as attributes to the span.
4
4
 
5
- Keys and values added to Baggage will appear on all subsequent child spans for a trace within this service *and* will be propagated to external services via propagation headers.
5
+ Keys and values added to Baggage will appear on all subsequent child spans, not the current active span, for a trace within this service *and* will be propagated to external services via propagation headers.
6
6
  If the external services also have a Baggage span processor, the keys and values will appear in those child spans as well.
7
7
 
8
8
  ⚠️ Waning ⚠️
@@ -13,7 +13,7 @@ Do not put sensitive information in Baggage.
13
13
 
14
14
  Install the gem using:
15
15
 
16
- ```shell
16
+ ```console
17
17
  gem install opentelemetry-processor-baggage
18
18
  ```
19
19
 
@@ -31,7 +31,7 @@ To install the instrumentation, add the gem to your Gemfile:
31
31
  gem 'opentelemetry-processor-baggage'
32
32
  ```
33
33
 
34
- Then add the processor to an SDK's configuration:
34
+ Then configure the span processor to copy all baggage entries:
35
35
 
36
36
  ```ruby
37
37
  require 'rubygems'
@@ -40,8 +40,11 @@ require 'bundler/setup'
40
40
  Bundler.require
41
41
 
42
42
  OpenTelemetry::SDK.configure do |c|
43
- # Add the BaggageSpanProcessor to the collection of span processors
44
- c.add_span_processor(OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new)
43
+ # Add the BaggageSpanProcessor to the collection of span processors and
44
+ # copy all baggage entries
45
+ c.add_span_processor(OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new(
46
+ OpenTelemetry::Processor::Baggage::ALLOW_ALL_BAGGAGE_KEYS
47
+ ))
45
48
 
46
49
  # Because the span processor list is no longer empty, the SDK will not use the
47
50
  # values in OTEL_TRACES_EXPORTER to instantiate exporters.
@@ -57,11 +60,32 @@ OpenTelemetry::SDK.configure do |c|
57
60
  end
58
61
  ```
59
62
 
63
+ Alternatively, you can provide a custom baggage key predicate to select which baggage keys you want to copy.
64
+
65
+ For example, to only copy baggage entries that start with `myapp.`:
66
+
67
+ ```ruby
68
+ OUR_BAGGAGE_KEY_PREFIX = 'myapp.'.freeze
69
+ OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new(
70
+ # a constant here improves performance
71
+ ->(baggage_key) { baggage_key.start_with?(OUR_BAGGAGE_KEY_PREFIX) }
72
+ )
73
+ ```
74
+
75
+ For example, to only copy baggage entries that match `myapp.`, `myapp1.` and `myapp42.`:
76
+
77
+ ```ruby
78
+ OUR_BAGGAGE_KEY_MATCHER = /\Amyapp\d*\./
79
+ OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new(
80
+ ->(baggage_key) { OUR_BAGGAGE_KEY_MATCHER.match?(baggage_key) }
81
+ )
82
+ ```
83
+
60
84
  ## How can I get involved?
61
85
 
62
86
  The `opentelemetry-processor-baggage` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`.
63
87
 
64
- The OpenTelemetry Ruby gems are maintained by the OpenTelemetry-Ruby special interest group (SIG). You can get involved by joining us in [GitHub Discussions][discussions-url] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
88
+ The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby special interest group (SIG). You can get involved by joining us on our [GitHub Discussions][discussions-url], [Slack Channel][slack-channel] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
65
89
 
66
90
  ## License
67
91
 
@@ -72,4 +96,5 @@ The `opentelemetry-instrumentation-sinatra` gem is distributed under the Apache
72
96
  [license-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/LICENSE
73
97
  [ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
74
98
  [community-meetings]: https://github.com/open-telemetry/community#community-meetings
99
+ [slack-channel]: https://cloud-native.slack.com/archives/C01NWKKMKMY
75
100
  [discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
@@ -10,13 +10,19 @@ require 'opentelemetry-sdk'
10
10
  module OpenTelemetry
11
11
  module Processor
12
12
  module Baggage
13
+ # A baggage key predicate that allows all keys to be added to the span as attributes.
14
+ ALLOW_ALL_BAGGAGE_KEYS = ->(_) { true }
15
+
13
16
  # The BaggageSpanProcessor reads key/values stored in Baggage in the
14
- # starting span's parent context and adds them as attributes to the span.
17
+ # starting span's parent context and adds them as attributes to the span,
18
+ # if a key matches a provided predicate lambda.
19
+ #
20
+ # Keys and values added to Baggage will appear on all subsequent child spans,
21
+ # not the current active span, for a trace within this service *and* will be
22
+ # propagated to external services via propagation headers.
15
23
  #
16
- # Keys and values added to Baggage will appear on all subsequent child spans
17
- # for a trace within this service *and* will be propagated to external services
18
- # via propagation headers. If the external services also have a Baggage span
19
- # processor, the keys and values will appear in those child spans as well.
24
+ # If the external services also have a Baggage span processor, the keys and
25
+ # values will appear in those child spans as well.
20
26
  #
21
27
  # ⚠️
22
28
  # To repeat: a consequence of adding data to Baggage is that the keys and
@@ -24,10 +30,16 @@ module OpenTelemetry
24
30
  # Do not put sensitive information in Baggage.
25
31
  # ⚠️
26
32
  #
27
- # @example
33
+ # @example Adding the BaggageSpanProcessor to the SDK, only add attributes for keys that start with 'myapp.'
34
+ # OUR_BAGGAGE_KEY_PREFIX = 'myapp.'.freeze
35
+ #
28
36
  # OpenTelemetry::SDK.configure do |c|
29
37
  # # Add the BaggageSpanProcessor to the collection of span processors
30
- # c.add_span_processor(OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new)
38
+ # c.add_span_processor(
39
+ # OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new(
40
+ # ->(key) { key.start_with?(OUR_BAGGAGE_KEY_PREFIX) } # a constant here improves performance
41
+ # )
42
+ # )
31
43
  #
32
44
  # # Because the span processor list is no longer empty, the SDK will not use the
33
45
  # # values in OTEL_TRACES_EXPORTER to instantiate exporters.
@@ -41,7 +53,31 @@ module OpenTelemetry
41
53
  # )
42
54
  # )
43
55
  # end
56
+ #
57
+ # @example Allow all Baggage keys to be added to the span as attributes
58
+ # OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new(
59
+ # # This processor provides a convenience predicate that allows all keys to be added as attributes.
60
+ # OpenTelemetry::Processor::Baggage::ALLOW_ALL_BAGGAGE_KEYS
61
+ # )
44
62
  class BaggageSpanProcessor < OpenTelemetry::SDK::Trace::SpanProcessor
63
+ # Create a new BaggageSpanProcessor that reads Baggage keys and values from the parent context
64
+ # and adds them as attributes to the span.
65
+ #
66
+ # @param [lambda] baggage_key_predicate A lambda that takes a baggage key [String] and returns true if
67
+ # the key should be added to the span as an attribute, false otherwise.
68
+ #
69
+ # @example Only add attributes for keys that start with a specific prefix
70
+ # OUR_BAGGAGE_KEY_PREFIX = 'myapp.'.freeze
71
+ # OpenTelemetry::Processor::Baggage::BaggageSpanProcessor.new(
72
+ # ->(key) { key.start_with?(OUR_BAGGAGE_KEY_PREFIX) } # a constant here improves performance
73
+ # )
74
+ def initialize(baggage_key_predicate)
75
+ raise ArgumentError, 'baggage_key_predicate must respond to :call (lambda/Proc)' unless baggage_key_predicate.respond_to?(:call)
76
+
77
+ @baggage_key_predicate = baggage_key_predicate
78
+ super()
79
+ end
80
+
45
81
  # Called when a `Span` is started, adds Baggage keys/values to the span as attributes.
46
82
  #
47
83
  # @param [Span] span the `Span` that just started, expected to conform
@@ -51,7 +87,11 @@ module OpenTelemetry
51
87
  def on_start(span, parent_context)
52
88
  return unless span.respond_to?(:add_attributes) && parent_context.is_a?(::OpenTelemetry::Context)
53
89
 
54
- span.add_attributes(::OpenTelemetry::Baggage.values(context: parent_context))
90
+ span.add_attributes(
91
+ ::OpenTelemetry::Baggage
92
+ .values(context: parent_context)
93
+ .select { |k, _v| @baggage_key_predicate.call(k) }
94
+ )
55
95
  end
56
96
 
57
97
  # Called when a Span is ended, does nothing.
@@ -15,7 +15,7 @@ module OpenTelemetry
15
15
  module Processor
16
16
  # Namespace for OpenTelemetry Baggage processor
17
17
  module Baggage
18
- VERSION = '0.1.0'
18
+ VERSION = '0.2.1'
19
19
  end
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-processor-baggage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-30 00:00:00.000000000 Z
11
+ date: 2024-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -100,28 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.62'
103
+ version: 1.68.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.62'
110
+ version: 1.68.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rubocop-performance
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '1.20'
117
+ version: 1.23.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '1.20'
124
+ version: 1.23.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: simplecov
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -168,11 +168,14 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
168
168
  licenses:
169
169
  - Apache-2.0
170
170
  metadata:
171
- changelog_uri: https://rubydoc.info/gems/opentelemetry-processor-baggage/0.1.0/file/CHANGELOG.md
171
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-processor-baggage/0.2.1/file/CHANGELOG.md
172
172
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/processor/baggage
173
173
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
174
- documentation_uri: https://rubydoc.info/gems/opentelemetry-processor-baggage/0.1.0
175
- post_install_message:
174
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-processor-baggage/0.2.1
175
+ post_install_message: |
176
+ Ruby 3.0 has reached EoL 2024-04-23. OTel Ruby Contrib gems will no longer accept new features or bug fixes for Ruby 3.0 after 2025-01-15. Please upgrade to Ruby 3.1 or higher to continue receiving updates.
177
+
178
+ Rails 6.1 has reached EoL 2024-10-01. OTel Ruby Contrib gems will no longer accept new features or bug fixes for Rails 6.1 after 2025-01-15. Please upgrade to Rails 7.0 or higher to continue receiving updates.
176
179
  rdoc_options: []
177
180
  require_paths:
178
181
  - lib