Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[email] document instrumentation #388

Merged
merged 3 commits into from
Sep 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions docs/services/emailservice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# email service

This service will send a confirmation email to the user when an order is placed.

[Email service source](../../src/emailservice/)

## Initialize SDK

You will need to require the core OpenTelemetry SDK and exporter Ruby gems, as
well as any gem that will be needed for auto-instrumentation libraries
(ie: Sinatra)

```ruby
require "opentelemetry/sdk"
require "opentelemetry/exporter/otlp"
require "opentelemetry/instrumentation/sinatra"
```

The Ruby SDK uses OpenTelemetry standard environment variables to configure
OTLP export, resource attributes, and service name automatically. When
initializing the OpenTelemetry SDK, you will also specify which
auto-instrumentation libraries to leverage (ie: Sinatra)

```ruby
OpenTelemetry::SDK.configure do |c|
puckpuck marked this conversation as resolved.
Show resolved Hide resolved
c.use "OpenTelemetry::Instrumentation::Sinatra"
end
```

## Traces

### Add attributes to auto-instrumented spans

Within the execution of auto-instrumented code you can get current span from
context.

```ruby
current_span = OpenTelemetry::Trace.current_span
```

Adding multiple attributes to a span is accomplished using `add_attributes` on
the span object.

```ruby
current_span.add_attributes({
"app.order.id" => data.order.order_id,
})
```

Adding only a single attribute can be accomplished using `set_attribute` on the
span object.

```ruby
span.set_attribute("app.email.recipient", data.email)
```

### Create new spans

New spans can be created and placed into active context using `in_span` from an
OpenTelemetry Tracer object. When used in conjunction with a `do..end` block,
the span will automatically be ended when the block ends execution.

```ruby
tracer = OpenTelemetry.tracer_provider.tracer('emailservice')
tracer.in_span("send_email") do |span|
# logic in context of span here
end
```

## Metrics

TBD

## Logs

TBD