traces-backend-open_telemetry 0.2.0 → 0.4.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/traces/backend/open_telemetry/interface.rb +81 -11
- data/lib/traces/backend/open_telemetry/version.rb +4 -1
- data/readme.md +24 -3
- data/releases.md +25 -0
- data.tar.gz.sig +0 -0
- metadata +5 -9
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b87e401f00f7dadeb4c3030d9abfd80be9a7343f7a61b8088886ff6ece86b9a2
|
4
|
+
data.tar.gz: 0ef5ed27b0a48492f672b7f4fc3b867387bffef46cf665fccf624252da8fbb04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0023923b237b02779db6c6bb35a9013b9751e04a9e3ea8098eb08de28db4b5797068abc2ec4ff2ea83dba2b5cf2fda6938710d99c07c39ed91eaac56f6f2e42d'
|
7
|
+
data.tar.gz: 5846bf33abdb432cd5c3d26334eb81891e98a43430fe005b41b01ee38b7ec9373e903b41fd945c0c8e3f35dba1550c32e32233ab1c3b951269a9cda29266f9ac
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -15,26 +15,49 @@ module Traces
|
|
15
15
|
# See <https://github.com/open-telemetry/opentelemetry-ruby> for more details.
|
16
16
|
TRACER = ::OpenTelemetry.tracer_provider.tracer(Traces::Backend::OpenTelemetry.name, Traces::Backend::OpenTelemetry::VERSION)
|
17
17
|
|
18
|
+
# Provides the interface implementation for OpenTelemetry tracing backend.
|
18
19
|
module Interface
|
20
|
+
# Creates a trace span with the given name and attributes.
|
21
|
+
# @parameter name [String] The name of the trace span.
|
22
|
+
# @parameter attributes [Hash | Nil] Optional attributes to attach to the span.
|
23
|
+
# @yields {|span| ...} The block to execute within the trace span.
|
24
|
+
# @returns [Object] The result of the block execution.
|
19
25
|
def trace(name, attributes: nil, &block)
|
20
26
|
TRACER.in_span(name, attributes: attributes&.transform_keys(&:to_s), &block)
|
21
27
|
end
|
22
28
|
|
29
|
+
# Sets the current trace context.
|
30
|
+
# @parameter context [Traces::Context | Nil] The trace context to set as current.
|
23
31
|
def trace_context=(context)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
if context
|
33
|
+
span_context = ::OpenTelemetry::Trace::SpanContext.new(
|
34
|
+
trace_id: context.trace_id,
|
35
|
+
span_id: context.parent_id,
|
36
|
+
trace_flags: ::OpenTelemetry::Trace::TraceFlags.from_byte(context.flags),
|
37
|
+
tracestate: context.state,
|
38
|
+
remote: context.remote?
|
39
|
+
)
|
40
|
+
|
41
|
+
span = ::OpenTelemetry::Trace.non_recording_span(span_context)
|
42
|
+
context = ::OpenTelemetry::Trace.context_with_span(span)
|
43
|
+
::OpenTelemetry::Context.attach(context)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Checks if there is currently an active trace span.
|
48
|
+
# @returns [Boolean] `true` if there is an active trace span, `false` otherwise.
|
49
|
+
def active?
|
50
|
+
# Check if there's a real active trace using OpenTelemetry's INVALID span:
|
51
|
+
::OpenTelemetry::Trace.current_span != ::OpenTelemetry::Trace::Span::INVALID
|
35
52
|
end
|
36
53
|
|
54
|
+
# Gets the current trace context from the active span.
|
55
|
+
# @parameter span [OpenTelemetry::Trace::Span] The span to extract context from, defaults to current span.
|
56
|
+
# @returns [Traces::Context | Nil] The trace context, or `nil` if no active trace.
|
37
57
|
def trace_context(span = ::OpenTelemetry::Trace.current_span)
|
58
|
+
# Return nil if no active trace (using INVALID span check):
|
59
|
+
return nil if span == ::OpenTelemetry::Trace::Span::INVALID
|
60
|
+
|
38
61
|
if span_context = span.context
|
39
62
|
flags = 0
|
40
63
|
|
@@ -51,6 +74,53 @@ module Traces
|
|
51
74
|
)
|
52
75
|
end
|
53
76
|
end
|
77
|
+
|
78
|
+
# Gets the current OpenTelemetry context.
|
79
|
+
# @returns [OpenTelemetry::Context] The current OpenTelemetry context.
|
80
|
+
def current_context
|
81
|
+
::OpenTelemetry::Context.current
|
82
|
+
end
|
83
|
+
|
84
|
+
# Executes code within the given context or attaches the context.
|
85
|
+
# @parameter context [OpenTelemetry::Context] The context to use.
|
86
|
+
# @yields {|| ...} Optional block to execute within the context.
|
87
|
+
# @returns [Object] The result of the block if given, otherwise the detach token.
|
88
|
+
def with_context(context)
|
89
|
+
if block_given?
|
90
|
+
::OpenTelemetry::Context.with_current(context) do
|
91
|
+
yield
|
92
|
+
end
|
93
|
+
else
|
94
|
+
::OpenTelemetry::Context.attach(context)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Injects trace context into headers for propagation.
|
99
|
+
# @parameter headers [Hash | Nil] Optional headers hash to inject into, defaults to new hash.
|
100
|
+
# @parameter context [OpenTelemetry::Context | Nil] Optional context to inject, defaults to current context.
|
101
|
+
# @returns [Hash | Nil] The headers with injected trace context, or `nil` if no injection occurred.
|
102
|
+
def inject(headers = nil, context = nil)
|
103
|
+
context ||= ::OpenTelemetry::Context.current
|
104
|
+
headers ||= Hash.new
|
105
|
+
|
106
|
+
count = headers.count
|
107
|
+
|
108
|
+
::OpenTelemetry.propagation.inject(headers, context: context)
|
109
|
+
|
110
|
+
if count == headers.count
|
111
|
+
# No injection was performed, so return nil:
|
112
|
+
headers = nil
|
113
|
+
end
|
114
|
+
|
115
|
+
return headers
|
116
|
+
end
|
117
|
+
|
118
|
+
# Extracts trace context from headers.
|
119
|
+
# @parameter headers [Hash] The headers to extract trace context from.
|
120
|
+
# @returns [OpenTelemetry::Context] The extracted context.
|
121
|
+
def extract(headers)
|
122
|
+
::OpenTelemetry.propagation.extract(headers)
|
123
|
+
end
|
54
124
|
end
|
55
125
|
end
|
56
126
|
|
data/readme.md
CHANGED
@@ -12,9 +12,30 @@ $ bundle add traces-backend-open_telemetry
|
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
Please see the [project documentation](https://github.com/socketry/traces-backend-open_telemetry) for more details.
|
16
|
+
|
17
|
+
- [Getting Started](https://github.com/socketry/traces-backend-open_telemetryguides/getting-started/index) - This guide explains how to get started with `traces-backend-open_telemetry` to send application traces to OpenTelemetry.
|
18
|
+
|
19
|
+
## Releases
|
20
|
+
|
21
|
+
Please see the [project releases](https://github.com/socketry/traces-backend-open_telemetryreleases/index) for all releases.
|
22
|
+
|
23
|
+
### v0.4.0
|
24
|
+
|
25
|
+
- Fixed `Traces.active?` to correctly return `false` when there is no active trace, instead of always returning `true`.
|
26
|
+
- Fixed `Traces.trace_context` to return `nil` when there is no active trace, instead of returning invalid Context objects.
|
27
|
+
|
28
|
+
### v0.3.0
|
29
|
+
|
30
|
+
- [New Context Propagation Interface](https://github.com/socketry/traces-backend-open_telemetryreleases/index#new-context-propagation-interface)
|
31
|
+
|
32
|
+
### v0.2.0
|
33
|
+
|
34
|
+
- Prefer to use `Tracer#in_span`.
|
35
|
+
|
36
|
+
### v0.1.0
|
37
|
+
|
38
|
+
- Complete implementation of traces backend for OpenTelemetry.
|
18
39
|
|
19
40
|
## Contributing
|
20
41
|
|
data/releases.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Releases
|
2
|
+
|
3
|
+
## v0.4.0
|
4
|
+
|
5
|
+
- Fixed `Traces.active?` to correctly return `false` when there is no active trace, instead of always returning `true`.
|
6
|
+
- Fixed `Traces.trace_context` to return `nil` when there is no active trace, instead of returning invalid Context objects.
|
7
|
+
|
8
|
+
## v0.3.0
|
9
|
+
|
10
|
+
### New Context Propagation Interface
|
11
|
+
|
12
|
+
This release adds comprehensive support for OpenTelemetry's context propagation system, enabling efficient inter-process and intra-process tracing with full W3C compliance.
|
13
|
+
|
14
|
+
- `Traces.current_context` - Capture the current trace context for local propagation between execution contexts (threads, fibers).
|
15
|
+
- `Traces.with_context(context)` - Execute code within a specific trace context, with automatic restoration when used with blocks.
|
16
|
+
- `Traces.inject(headers = nil, context = nil)` - Inject W3C Trace Context and Baggage headers into a headers hash for distributed propagation.
|
17
|
+
- `Traces.extract(headers)` - Extract trace context from W3C Trace Context headers.
|
18
|
+
|
19
|
+
## v0.2.0
|
20
|
+
|
21
|
+
- Prefer to use `Tracer#in_span`.
|
22
|
+
|
23
|
+
## v0.1.0
|
24
|
+
|
25
|
+
- Complete implementation of traces backend for OpenTelemetry.
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traces-backend-open_telemetry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain:
|
11
10
|
- |
|
@@ -37,7 +36,7 @@ cert_chain:
|
|
37
36
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
38
37
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
39
38
|
-----END CERTIFICATE-----
|
40
|
-
date:
|
39
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
41
40
|
dependencies:
|
42
41
|
- !ruby/object:Gem::Dependency
|
43
42
|
name: opentelemetry-api
|
@@ -67,8 +66,6 @@ dependencies:
|
|
67
66
|
- - "~>"
|
68
67
|
- !ruby/object:Gem::Version
|
69
68
|
version: '0.10'
|
70
|
-
description:
|
71
|
-
email:
|
72
69
|
executables: []
|
73
70
|
extensions: []
|
74
71
|
extra_rdoc_files: []
|
@@ -78,12 +75,12 @@ files:
|
|
78
75
|
- lib/traces/backend/open_telemetry/version.rb
|
79
76
|
- license.md
|
80
77
|
- readme.md
|
78
|
+
- releases.md
|
81
79
|
homepage: https://github.com/socketry/traces-backend-open_telemetry
|
82
80
|
licenses:
|
83
81
|
- MIT
|
84
82
|
metadata:
|
85
83
|
source_code_uri: https://github.com/socketry/traces-backend-open_telemetry.git
|
86
|
-
post_install_message:
|
87
84
|
rdoc_options: []
|
88
85
|
require_paths:
|
89
86
|
- lib
|
@@ -91,15 +88,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
88
|
requirements:
|
92
89
|
- - ">="
|
93
90
|
- !ruby/object:Gem::Version
|
94
|
-
version: '3.
|
91
|
+
version: '3.2'
|
95
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
93
|
requirements:
|
97
94
|
- - ">="
|
98
95
|
- !ruby/object:Gem::Version
|
99
96
|
version: '0'
|
100
97
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
102
|
-
signing_key:
|
98
|
+
rubygems_version: 3.6.9
|
103
99
|
specification_version: 4
|
104
100
|
summary: A traces backend for Open Telemetry.
|
105
101
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|