Skip to content

Commit fe46f3d

Browse files
committed
Fix: Add Sinatra documentation & small refactor
1 parent 0d73d7b commit fe46f3d

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

instrumentation/sinatra/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,21 @@ The `opentelemetry-instrumentation-sinatra` gem is distributed under the Apache
7272
[community-meetings]: https://github.com/open-telemetry/community#community-meetings
7373
[slack-channel]: https://cloud-native.slack.com/archives/C01NWKKMKMY
7474
[discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
75+
76+
## HTTP semantic convention stability
77+
78+
In the OpenTelemetry ecosystem, HTTP semantic conventions have now reached a stable state. However, the initial Rack instrumentation was introduced before this stability was achieved, which resulted in HTTP attributes being based on an older version of the semantic conventions.
79+
80+
To facilitate the migration to stable semantic conventions, you can use the `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable. This variable allows you to opt-in to the new stable conventions, ensuring compatibility and future-proofing your instrumentation.
81+
82+
Sinatra instrumentaion installs Rack middleware, but the middleware version it installs depends on which `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable is set.
83+
84+
When setting the value for `OTEL_SEMCONV_STABILITY_OPT_IN`, you can specify which conventions you wish to adopt:
85+
86+
- `http` - Emits the stable HTTP and networking conventions and ceases emitting the old conventions previously emitted by the instrumentation.
87+
- `http/dup` - Emits both the old and stable HTTP and networking conventions, enabling a phased rollout of the stable semantic conventions.
88+
- Default behavior (in the absence of either value) is to continue emitting the old HTTP and networking conventions the instrumentation previously emitted.
89+
90+
During the transition from old to stable conventions, Rack instrumentation code comes in three patch versions: `dup`, `old`, and `stable`. These versions are identical except for the attributes they send. Any changes to Rack instrumentation should consider all three patches.
91+
92+
For additional information on migration, please refer to our [documentation](https://opentelemetry.io/docs/specs/semconv/non-normative/http-migration/).

instrumentation/sinatra/example/config.ru

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,9 @@ class App < Sinatra::Base
4747
end
4848
end
4949

50+
# Rack instrumentation is moving through the process of migrating to the new HTTP semantic
51+
# conventions. In this example, we will use the old HTTP conventions by patching the Rack
52+
# middleware that uses the old conventions. See README: HTTP Semantic Conventions for more
53+
# information.
5054
use(*OpenTelemetry::Instrumentation::Rack::Instrumentation.instance.middleware_args_old)
5155
run App

instrumentation/sinatra/lib/opentelemetry/instrumentation/sinatra/instrumentation.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
5151
end
5252

5353
def install_middleware(app)
54-
stability_opt_in = ENV.fetch('OTEL_SEMCONV_STABILITY_OPT_IN', '')
55-
values = stability_opt_in.split(',').map(&:strip)
56-
5754
if config[:install_rack]
55+
stability_opt_in = ENV.fetch('OTEL_SEMCONV_STABILITY_OPT_IN', '')
56+
values = stability_opt_in.split(',').map(&:strip)
57+
5858
if values.include?('http/dup')
5959
app.use(*OpenTelemetry::Instrumentation::Rack::Instrumentation.instance.middleware_args_dup)
6060
elsif values.include?('http')

0 commit comments

Comments
 (0)