Skip to content

Commit f0738fa

Browse files
ahayworthfbogsany
andauthored
docs: Update docs to rely more on environment variable configuration (#874)
This PR updates our documentation in a few ways: - Replaces some outdated configuration examples referencing a tracer factory - Cleans up a reference to a non-existent LMDB example - Sets the console span exporter for all current instrumentation examples - Updates docs to reflect how to configure things via the environment whenever possible or reasonable. Note that this means our examples may not flush to the console since the BatchSpanProcessor is selected by default. I think this is okay, honestly, but if it comes up we could figure out a way to select the SimpleSpanProcessor (as some examples were doing) via the environment. Fixes #872 Co-authored-by: Francis Bogsanyi <[email protected]>
1 parent f7cdc41 commit f0738fa

File tree

25 files changed

+88
-62
lines changed

25 files changed

+88
-62
lines changed

api/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ Then, use the OpenTelemetry interfaces to produces traces and other telemetry da
2929
```ruby
3030
require 'opentelemetry'
3131

32-
# Obtain the current default tracer factory
33-
factory = OpenTelemetry.tracer_factory
32+
# Obtain the current default tracer provider
33+
provider = OpenTelemetry.tracer_provider
3434

3535
# Create a trace
36-
tracer = factory.tracer('my_app', '1.0')
36+
tracer = provider.tracer('my_app', '1.0')
3737

3838
# Record spans
3939
tracer.in_span('my_task') do |task_span|

exporter/jaeger/README.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,27 @@ Then, configure the SDK to use a Jaeger exporter as a span processor, and use th
3131
require 'opentelemetry/sdk'
3232
require 'opentelemetry/exporter/jaeger'
3333

34-
# Configure the sdk with custom export
35-
OpenTelemetry::SDK.configure do |c|
36-
c.add_span_processor(
37-
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
38-
OpenTelemetry::Exporter::Jaeger::AgentExporter.new(host: '127.0.0.1', port: 6831)
39-
# Alternatively, for the collector exporter:
40-
# exporter: OpenTelemetry::Exporter::Jaeger::CollectorExporter.new(endpoint: 'http://192.168.0.1:14268/api/traces')
41-
)
42-
)
43-
c.service_name = 'jaeger-example'
44-
c.service_version = '0.6.0'
45-
end
34+
# Configure the sdk with the Jaeger collector exporter
35+
ENV['OTEL_TRACES_EXPORTER'] = 'jaeger'
36+
37+
ENV['OTEL_SERVICE_NAME'] = 'jaeger-example'
38+
ENV['OTEL_SERVICE_VERSION'] = '0.6.0'
39+
40+
# The exporter will connect to localhost:6381 by default. To change:
41+
# ENV['OTEL_EXPORTER_JAEGER_AGENT_HOST'] = 'some.other.host'
42+
# ENV['OTEL_EXPORTER_JAEGER_AGENT_PORT'] = 12345
43+
44+
# The SDK reads the environment for configuration, so no additional configuration is needed:
45+
OpenTelemetry::SDK.configure
46+
47+
# If you need to use the Jaeger Agent exporter, you will need to configure many things manually:
48+
# OpenTelemetry::SDK.configure do |c|
49+
# c.add_span_processor(
50+
# OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
51+
# OpenTelemetry::Exporter::Jaeger::AgentExporter.new(host: '127.0.0.1', port: 6831)
52+
# )
53+
# )
54+
# end
4655

4756
# To start a trace you need to get a Tracer from the TracerProvider
4857
tracer = OpenTelemetry.tracer_provider.tracer('my_app_or_gem', '0.1.0')

exporter/otlp/README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@ Then, configure the SDK to use the OTLP exporter as a span processor, and use th
3535
require 'opentelemetry/sdk'
3636
require 'opentelemetry/exporter/otlp'
3737

38-
# Configure the sdk with custom export
39-
OpenTelemetry::SDK.configure do |c|
40-
c.add_span_processor(
41-
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
42-
OpenTelemetry::Exporter::OTLP::Exporter.new(
43-
compression: 'gzip'
44-
)
45-
)
46-
)
47-
end
38+
# The OTLP exporter is the default, so no configuration is needed.
39+
# However, it could be manually selected via an environment variable if required:
40+
#
41+
# ENV['OTEL_TRACES_EXPORTER'] = 'otlp'
42+
#
43+
# You may also configure various settings via environment variables:
44+
# ENV['OTEL_EXPORTER_OTLP_COMPRESSION'] = 'gzip'
45+
46+
OpenTelemetry::SDK.configure
4847

4948
# To start a trace you need to get a Tracer from the TracerProvider
5049
tracer = OpenTelemetry.tracer_provider.tracer('my_app_or_gem', '0.1.0')
@@ -67,7 +66,7 @@ For additional examples, see the [examples on github][examples-github].
6766

6867
## How can I configure the OTLP exporter?
6968

70-
The collector exporter can be configured explicitly in code, as shown above, or via environment variables. The configuration parameters, environment variables, and defaults are shown below.
69+
The collector exporter can be configured explicitly in code, or via environment variables as shown above. The configuration parameters, environment variables, and defaults are shown below.
7170

7271
| Parameter | Environment variable | Default |
7372
| ------------------- | -------------------------------------------- | ----------------------------------- |

exporter/zipkin/README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@ Then, configure the SDK to use a zipkin exporter as a span processor, and use th
3131
require 'opentelemetry/sdk'
3232
require 'opentelemetry/exporter/zipkin'
3333

34-
# Configure the sdk with custom export
35-
OpenTelemetry::SDK.configure do |c|
36-
c.add_span_processor(
37-
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
38-
OpenTelemetry::Exporter::Zipkin::Exporter.new(endpoint: 'http://192.168.0.1:9411/api/v2/spans' )
39-
)
40-
)
41-
c.service_name = 'zipkin-example'
42-
c.service_version = '0.15.0'
43-
end
34+
# Select the zipkin exporter via environmental variables
35+
ENV['OTEL_TRACES_EXPORTER'] = 'zipkin'
36+
37+
ENV['OTEL_SERVICE_NAME'] = 'zipkin-example'
38+
ENV['OTEL_SERVICE_VERSION'] = '0.15.0'
39+
40+
# The zipkin expects an exporter running on localhost:9411 - you may override this if needed:
41+
# ENV['OTEL_EXPORTER_ZIPKIN_ENDPOINT'] = 'http://some.other.host:12345'
4442

4543
# To start a trace you need to get a Tracer from the TracerProvider
4644
tracer = OpenTelemetry.tracer_provider.tracer('my_app_or_gem', '0.1.0')
@@ -63,7 +61,7 @@ For additional examples, see the [examples on github][examples-github].
6361

6462
## How can I configure the Zipkin exporter?
6563

66-
The collector exporter can be configured explicitly in code, as shown above, or via environment variables. The configuration parameters, environment variables, and defaults are shown below.
64+
The collector exporter can be configured explicitly in code, or via environment variables as shown above. The configuration parameters, environment variables, and defaults are shown below.
6765

6866
| Parameter | Environment variable | Default |
6967
| ----------- | --------------------------------------| -------------------------- |

instrumentation/bunny/example/bunny.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111

1212
require 'bunny'
1313

14-
span_processor = OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
15-
OpenTelemetry::SDK::Trace::Export::ConsoleSpanExporter.new
16-
)
17-
14+
ENV['OTEL_TRACES_EXPORTER'] = 'console'
1815
OpenTelemetry::SDK.configure do |c|
1916
c.use 'OpenTelemetry::Instrumentation::Bunny'
20-
c.add_span_processor(span_processor)
2117
end
2218

2319
# Start a communication session with RabbitMQ

instrumentation/concurrent_ruby/example/concurrent_ruby.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
Bundler.require
77

8+
ENV['OTEL_TRACES_EXPORTER'] = 'console'
89
OpenTelemetry::SDK.configure do |c|
910
c.use 'OpenTelemetry::Instrumentation::ConcurrentRuby'
1011
end

instrumentation/dalli/example/dalli.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
Bundler.require
77

8+
ENV['OTEL_TRACES_EXPORTER'] = 'console'
89
OpenTelemetry::SDK.configure do |c|
910
c.use 'OpenTelemetry::Instrumentation::Dalli'
1011
end

instrumentation/delayed_job/example/delayed_job.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
Bundler.require
1111

12+
ENV['OTEL_TRACES_EXPORTER'] = 'console'
1213
OpenTelemetry::SDK.configure do |c|
1314
c.use 'OpenTelemetry::Instrumentation::DelayedJob'
1415
end

instrumentation/ethon/example/ethon.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
Bundler.require
77

8+
ENV['OTEL_TRACES_EXPORTER'] = 'console'
89
OpenTelemetry::SDK.configure do |c|
910
c.use 'OpenTelemetry::Instrumentation::Ethon'
1011
end

instrumentation/excon/example/excon.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
Bundler.require
77

8+
ENV['OTEL_TRACES_EXPORTER'] = 'console'
89
OpenTelemetry::SDK.configure do |c|
910
c.use 'OpenTelemetry::Instrumentation::Excon'
1011
end

0 commit comments

Comments
 (0)