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

Add basic OpenTelemetry support #1876

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
0b8eeb6
Add basic OpenTelemetry support
mjq Aug 26, 2022
07f6b81
Move to config.instrumenter - values :sentry/:otel instead of auto_in…
sl0thentr0py Oct 10, 2022
6a05daf
Revert scope.set_trace and rack changes; use rack_env instead
sl0thentr0py Oct 10, 2022
af71cac
Merge remote-tracking branch 'origin/master' into mjq/hackweek-otel
sl0thentr0py Oct 10, 2022
ff707e3
Also add scope.baggage for consistency
sl0thentr0py Oct 10, 2022
781793b
Make net/http conditional cleaner
sl0thentr0py Oct 10, 2022
cb6b91f
Add instrumenter checks to all other start_transaction's
sl0thentr0py Oct 17, 2022
e7b2802
Missing init guard in net/http
sl0thentr0py Oct 17, 2022
84e7949
DWIP
sl0thentr0py Oct 18, 2022
238e447
Merge remote-tracking branch 'origin/master' into mjq/hackweek-otel
sl0thentr0py Oct 19, 2022
0b21d4d
Revert instrumenter checks at call sites
sl0thentr0py Oct 20, 2022
550f015
Merge remote-tracking branch 'origin/master' into mjq/hackweek-otel
sl0thentr0py Oct 21, 2022
9f8ce8d
Guard with_child_span with instrumenter check
sl0thentr0py Oct 21, 2022
c7ff027
Make with_child_span blocks safe if span is nil
sl0thentr0py Oct 21, 2022
e3199ca
WIP
sl0thentr0py Oct 21, 2022
f39713a
Set contexts.otel as per spec on transaction
sl0thentr0py Oct 21, 2022
26127e5
Replace caller with checking net.peer.name for HTTP spans
sl0thentr0py Oct 21, 2022
d691b0f
Simplify contexts.otel
sl0thentr0py Oct 21, 2022
551809f
Use trace_id/span_id/parent_span_id from otel
sl0thentr0py Oct 27, 2022
542a019
CHANGELOG
sl0thentr0py Oct 27, 2022
7ab8e1e
Merge remote-tracking branch 'origin/master' into mjq/hackweek-otel
sl0thentr0py Oct 27, 2022
aecc946
Merge remote-tracking branch 'origin/master' into mjq/hackweek-otel
sl0thentr0py Oct 27, 2022
0cd4b7b
Some cleanup
sl0thentr0py Oct 27, 2022
c8f690c
Use otel timestamps
sl0thentr0py Oct 28, 2022
904b138
update_span_with_otel_data http
sl0thentr0py Oct 31, 2022
6f22b69
Add db statement as description
sl0thentr0py Nov 3, 2022
3f11d59
Merge remote-tracking branch 'origin/master' into mjq/hackweek-otel
sl0thentr0py Nov 4, 2022
fcb843b
Add sentry-opentelemetry gem
sl0thentr0py Nov 4, 2022
91a525d
Merge remote-tracking branch 'origin/master' into mjq/hackweek-otel
sl0thentr0py Nov 7, 2022
8508d2f
Use otel classes and constants
sl0thentr0py Nov 7, 2022
a31a728
sentry_trace logic extract
sl0thentr0py Nov 7, 2022
7f15f96
sentry_trace propagator WIP
sl0thentr0py Nov 7, 2022
f15b9a8
Revert scope / net http changes
sl0thentr0py Nov 8, 2022
4bf33d7
Remove scope from on_start, use span_map entirely
sl0thentr0py Nov 8, 2022
6529a5c
Expose contexts on transaction
sl0thentr0py Nov 8, 2022
5db849a
Update readme
sl0thentr0py Nov 8, 2022
aba4e19
Make SpanProcessor singleton
sl0thentr0py Nov 9, 2022
abc0e5c
Finished sentry-trace propagator
sl0thentr0py Nov 9, 2022
f75dab2
Add baggage propagation
sl0thentr0py Nov 9, 2022
6b2b00a
Merge remote-tracking branch 'origin/master' into mjq/hackweek-otel
sl0thentr0py Nov 9, 2022
7be3071
Add otel.kind to data, fix gemspec after merge
sl0thentr0py Nov 10, 2022
0ba42c2
Add to ci
sl0thentr0py Nov 11, 2022
c3ede50
Merge remote-tracking branch 'origin/master' into mjq/hackweek-otel
sl0thentr0py Nov 11, 2022
7ec4748
fuck old versions
sl0thentr0py Nov 11, 2022
ab57961
Make danger happy
sl0thentr0py Nov 11, 2022
b84d78b
on_start specs
sl0thentr0py Nov 15, 2022
bbbe258
Finished on_start specs
sl0thentr0py Nov 16, 2022
1e5b0fe
Finished span_processor spec
sl0thentr0py Nov 16, 2022
54fe113
Start propagator spec
sl0thentr0py Nov 17, 2022
e10476d
Fix hex pack in extract; finish propagator specs
sl0thentr0py Nov 18, 2022
8a1c99f
Merge remote-tracking branch 'origin/master' into mjq/hackweek-otel
sl0thentr0py Nov 18, 2022
944f2ed
Fix gem build warning
sl0thentr0py Nov 18, 2022
dc7b0c6
Add sentry-opentelemetry to craft/release flow
sl0thentr0py Nov 18, 2022
2c431c1
Just disable subscribers for rails and remove safe span access
sl0thentr0py Nov 22, 2022
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
1 change: 1 addition & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ targets:
'gem:sentry-rails':
'gem:sentry-sidekiq':
'gem:sentry-delayed_job':
'gem:sentry-opentelemetry':
- name: github
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

### Features

- Add OpenTelemetry `SpanProcessor` TODO-neel expand [#1876](https://github.com/getsentry/sentry-ruby/pull/1876)

## 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

First, make sure to initialize Sentry before OpenTelemetry by prefixing your initializers and set the `instrumenter` to `:otel`.
```ruby
# config/initializers/01_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/02_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
6 changes: 6 additions & 0 deletions sentry-opentelemetry/lib/sentry-opentelemetry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require "sentry-ruby"
require "opentelemetry-sdk"

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