Skip to content

Commit

Permalink
Add new sentry-opentelemetry gem (#1948)
Browse files Browse the repository at this point in the history
### Summary
* new gem `sentry-opentelemetry` to be used as described [here](https://github.com/getsentry/sentry-ruby/blob/neel/otel-gem/sentry-opentelemetry/README.md#getting-started)
* all sentry instrumentation will be disabled by a new `config.instrumeneter` option so that sentry and otel do not step on each other's toes
* the 2 main things are
   * a [`SpanProcessor`](https://github.com/getsentry/sentry-ruby/blob/neel/otel-gem/sentry-opentelemetry/lib/sentry/opentelemetry/span_processor.rb) that hooks into `on_start/on_finish` whenever OpenTelemetry starts/finishes a span. This in turn creates sentry transactions/spans as necessary and keeps track of them in an internal `span_map` hash.
   * a [`Propagator`](https://github.com/getsentry/sentry-ruby/blob/neel/otel-gem/sentry-opentelemetry/lib/sentry/opentelemetry/propagator.rb) to make sure distributed tracing and dynamic sampling work by hooking into `inject/extract` for incoming/outgoing sentry-trace/baggage header management.

---
### Spec
https://develop.sentry.dev/sdk/performance/opentelemetry/
  • Loading branch information
sl0thentr0py authored Dec 1, 2022
1 parent 3567021 commit 1b39e7e
Show file tree
Hide file tree
Showing 23 changed files with 1,021 additions and 3 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/sentry_opentelemetry_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: sentry-opentelemetry Test

on:
workflow_dispatch:
push:
branches:
- master
- \d+-\d+
pull_request:
# Cancel in progress workflows on pull_requests.
# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
test:
defaults:
run:
working-directory: sentry-opentelemetry
name: Ruby ${{ matrix.ruby_version }} & OpenTelemetry ${{ matrix.opentelemetry_version }}, options - ${{ toJson(matrix.options) }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
ruby_version: [2.6, 2.7, '3.0', head, jruby]
# opentelemetry_version: [1.2.0]
os: [ubuntu-latest]
include:
- { os: ubuntu-latest, ruby_version: 3.1, options: { rubyopt: "--enable-frozen-string-literal --debug=frozen-string-literal" } }
- { os: ubuntu-latest, ruby_version: 3.1, options: { codecov: 1 } }
steps:
- uses: actions/checkout@v1

- name: Set up Ruby ${{ matrix.ruby_version }}
uses: ruby/setup-ruby@8ddb7b3348b3951590db24c346e94ebafdabc926
with:
ruby-version: ${{ matrix.ruby_version }}

- name: Run specs
env:
RUBYOPT: ${{ matrix.options.rubyopt }}
OPENTELEMETRY_VERSION: ${{ matrix.opentelemetry_version }}
run: |
bundle install --jobs 4 --retry 3
bundle exec rake
- name: Upload Coverage
if: ${{ matrix.options.codecov }}
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t ${CODECOV_TOKEN} -R `pwd` -f coverage/coverage.xml
2 changes: 1 addition & 1 deletion .scripts/batch_build.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INTEGRATIONS = %w(sentry-rails sentry-sidekiq sentry-delayed_job sentry-resque)
INTEGRATIONS = %w(sentry-rails sentry-sidekiq sentry-delayed_job sentry-resque sentry-opentelemetry)
GEMS = %w(sentry-ruby) + INTEGRATIONS

GEMS.each do |gem_name|
Expand Down
2 changes: 1 addition & 1 deletion .scripts/batch_release.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INTEGRATIONS = %w(sentry-rails sentry-sidekiq sentry-delayed_job sentry-resque)
INTEGRATIONS = %w(sentry-rails sentry-sidekiq sentry-delayed_job sentry-resque sentry-opentelemetry)
GEMS = %w(sentry-ruby) + INTEGRATIONS

def get_version_file_name(gem_name)
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Unreleased
## 5.7.0

### Features

Expand All @@ -8,6 +8,8 @@
- Add OpenTelemetry support with new `sentry-opentelemetry` gem
- Add `config.instrumenter` to switch between `:sentry` and `:otel` instrumentation [#1944](https://github.com/getsentry/sentry-ruby/pull/1944)

The new `sentry-opentelemetry` gem adds support to automatically integrate OpenTelemetry performance tracing with Sentry. [Give it a try](https://github.com/getsentry/sentry-ruby/tree/neel/otel-gem/sentry-opentelemetry#getting-started) and let us know if you have any feedback or problems with using it.

## 5.6.0

### Features
Expand Down
11 changes: 11 additions & 0 deletions sentry-opentelemetry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
.rspec_status
3 changes: 3 additions & 0 deletions sentry-opentelemetry/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--format documentation
--color
--require spec_helper
74 changes: 74 additions & 0 deletions sentry-opentelemetry/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [https://contributor-covenant.org/version/1/4][version]

[homepage]: https://contributor-covenant.org
[version]: https://contributor-covenant.org/version/1/4/
24 changes: 24 additions & 0 deletions sentry-opentelemetry/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
source "https://rubygems.org"
git_source(:github) { |name| "https://github.com/#{name}.git" }

# Specify your gem's dependencies in sentry-ruby.gemspec
gemspec

gem "rake", "~> 12.0"
gem "rspec", "~> 3.0"
gem 'simplecov'
gem "simplecov-cobertura", "~> 1.4"
gem "rexml"

# opentelemetry_version = ENV["OPENTELEMETRY_VERSION"]
# opentelemetry_version = "1.2.0" if opentelemetry_version.nil?
# gem "opentelemetry-sdk", "~> #{opentelemetry_version}"

gem "opentelemetry-sdk"
gem "opentelemetry-instrumentation-rails"

gem "sentry-ruby", path: "../sentry-ruby"

gem "object_tracer"
gem "debug", github: "ruby/debug", platform: :ruby if RUBY_VERSION.to_f >= 2.6
gem "pry"
21 changes: 21 additions & 0 deletions sentry-opentelemetry/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 Sentry

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
3 changes: 3 additions & 0 deletions sentry-opentelemetry/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
bundle install
gem build sentry-opentelemetry.gemspec
65 changes: 65 additions & 0 deletions sentry-opentelemetry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<p align="center">
<a href="https://sentry.io" target="_blank" align="center">
<img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
</a>
<br>
</p>

# sentry-opentelemetry, the OpenTelemetry integration for Sentry's Ruby client

---


[![Gem Version](https://img.shields.io/gem/v/sentry-opentelemetry.svg)](https://rubygems.org/gems/sentry-opentelemetry)
![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-opentelemetry%20Test/badge.svg)
[![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master)
[![Gem](https://img.shields.io/gem/dt/sentry-opentelemetry.svg)](https://rubygems.org/gems/sentry-opentelemetry/)
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=sentry-opentelemetry&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sentry-opentelemetry&package-manager=bundler&version-scheme=semver)


[Documentation](https://docs.sentry.io/platforms/ruby/guides/opentelemetry/) | [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues) | [Forum](https://forum.sentry.io/) | IRC: irc.freenode.net, #sentry

The official Ruby-language client and integration layer for the [Sentry](https://github.com/getsentry/sentry) error reporting API.


## Getting Started

### Install

```ruby
gem "sentry-ruby"
gem "sentry-rails"
gem "sentry-opentelemetry"

gem "opentelemetry-sdk"
gem "opentelemetry-instrumentation-all"
```

### Configuration

Initialize Sentry for tracing and set the `instrumenter` to `:otel`.
```ruby
# config/initializers/sentry.rb

Sentry.init do |config|
config.dsn = "MY_DSN"
config.traces_sample_rate = 1.0
config.instrumenter = :otel
end
```

This will disable all Sentry instrumentation and rely on the chosen OpenTelemetry tracers for creating spans.

Next, configure OpenTelemetry as per your needs and hook in the Sentry span processor and propagator.

```ruby
# config/initializers/otel.rb

OpenTelemetry::SDK.configure do |c|
c.use_all
c.add_span_processor(Sentry::OpenTelemetry::SpanProcessor.instance)
end

OpenTelemetry.propagation = Sentry::OpenTelemetry::Propagator.new
```

8 changes: 8 additions & 0 deletions sentry-opentelemetry/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec).tap do |task|
task.rspec_opts = "--order rand"
end

task :default => :spec
15 changes: 15 additions & 0 deletions sentry-opentelemetry/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "sentry/opentelemetry"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require "irb"
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions sentry-opentelemetry/bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
8 changes: 8 additions & 0 deletions sentry-opentelemetry/lib/sentry-opentelemetry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

require "sentry-ruby"
require "opentelemetry-sdk"

require "sentry/opentelemetry/version"
require "sentry/opentelemetry/span_processor"
require "sentry/opentelemetry/propagator"
Loading

0 comments on commit 1b39e7e

Please sign in to comment.