Skip to content

Commit

Permalink
squash: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
arielvalentin committed Oct 10, 2023
1 parent 7159983 commit 38bbe0b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
27 changes: 27 additions & 0 deletions instrumentation/active_job/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ Attributes that are specific to this instrumentation are recorded under `rails.a
| `rails.active_job.priority` | Integer | |
| `rails.active_job.scheduled_at` | Float | _Subject to be converted to a Span Event_ |

## Differences between ActiveJob versions

### ActiveJob 6.1

`perform.active_job` events do not include timings for `ActiveJob` callbacks therefore time spent in `before` and `after` hooks will be missing

`ActiveJob::Base#executions` start at `1`.

### ActiveJob 7+

`perform.active_job` no longer includes exceptions handled using `rescue_from` in the payload.

In order to preseve this behavior you will have to update the span yourself, e.g.

```ruby
rescue_from MyCustomError do |e|
# Custom code to handle the error
span = OpenTelemetry::Instrumentation::ActiveJob.current_span
span.record_exception(e)
span.status = OpenTelemetry::Trace::Status.error('Job failed')
end
```

`ActiveJob::Base#executions` start at `0` instead of `1` as it did in v6.1.



## Examples

Example usage can be seen in the `./example/active_job.rb` file [here](https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/instrumentation/active_job/example/active_job.rb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ module Handlers
# This class provides default template methods that derived classes may override to generate spans and register contexts.
class Default
# @param tracer [OpenTelemetry::Trace::Tracer] to generate spans
# @param parent_span_provider [Object] provides access to the top most parent span (usually the ingress span)
# @param mapper [Callable] converts ActiveSupport::Notifications payloads to span attributes
# @param config [Hash] of instrumentation options
def initialize(tracer, mapper, config)
def initialize(tracer, parent_span_provider, mapper, config)
@tracer = tracer
@mapper = mapper
@config = config
@ingress_span_provider = OpenTelemetry::Instrumentation::ActiveJob
@parent_span_provider = parent_span_provider
end

# Invoked by ActiveSupport::Notifications at the start of the instrumentation block
Expand Down Expand Up @@ -97,9 +98,9 @@ def finish_span(span, tokens)
# @param [OpenTelemetry::Trace::Span] the currently active span used to record the exception and set the status
def on_exception(exception, span)
status = OpenTelemetry::Trace::Status.error(exception.message)
@ingress_span_provider.current_span.status = status
span&.record_exception(exception)
span&.status = status
@parent_span_provider.current_span.status = status
end
end
end
Expand Down

0 comments on commit 38bbe0b

Please sign in to comment.