Skip to content

Commit

Permalink
Merge branch 'main' into aj-semconv
Browse files Browse the repository at this point in the history
  • Loading branch information
plantfansam authored Aug 1, 2023
2 parents eebb97c + 6c03ff8 commit 4805d8f
Show file tree
Hide file tree
Showing 22 changed files with 802 additions and 439 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,6 @@ updates:
schedule:
interval: weekly
- package-ecosystem: bundler
directory: "/resource_detectors/container"
directory: "/resources/container"
schedule:
interval: weekly
2 changes: 1 addition & 1 deletion .github/workflows/ci-contrib-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
matrix:
gem:
- resource_detectors
- resource_detectors-container
- resource-detector-container
os:
- ubuntu-latest
- macos-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-contrib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
matrix:
gem:
- resource_detectors
- resource_detectors-container
- resource-detector-container
os:
- ubuntu-latest
name: "opentelemetry-${{ matrix.gem }} / ${{ matrix.os }}"
Expand Down
6 changes: 3 additions & 3 deletions .toys/.data/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ gems:
version_rb_path: lib/opentelemetry/resource/detectors/version.rb
version_constant: [OpenTelemetry, Resource, Detectors, VERSION]

- name: opentelemetry-resource_detectors-container
- name: opentelemetry-resource-detector-container
directory: resources/container
version_rb_path: lib/opentelemetry/resource/detectors/container/version.rb
version_constant: [OpenTelemetry, Resource, Detectors, Container, VERSION]
version_rb_path: lib/opentelemetry/resource/detector/container/version.rb
version_constant: [OpenTelemetry, Resource, Detector, Container, VERSION]
6 changes: 5 additions & 1 deletion instrumentation/graphql/Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ appraise 'graphql-1.13' do
end

appraise 'graphql-2.0.17' do
gem 'graphql', '~> 2.0.17'
gem 'graphql', '2.0.17'
end

appraise 'graphql-2.0.18' do
gem 'graphql', '2.0.18'
end

appraise 'graphql-2.x' do
Expand Down
4 changes: 4 additions & 0 deletions instrumentation/graphql/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release History: opentelemetry-instrumentation-graphql

### v0.26.4 / 2023-08-01

* FIXED: GraphQL tests and installation

### v0.26.3 / 2023-07-29

* FIXED: GraphQL validate events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ module GraphQL
class Instrumentation < OpenTelemetry::Instrumentation::Base
compatible do
if config[:legacy_tracing]
legacy_tracing_requirement_satisfied?
supports_legacy_tracer?
else
Gem::Requirement.new('>= 2.0.18', '< 3.0.0').satisfied_by?(gem_version)
supports_new_tracer?
end
end

Expand All @@ -33,8 +33,12 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
defined?(::GraphQL)
end

def legacy_tracing_requirement_satisfied?
Gem::Requirement.new('<= 2.0.17').satisfied_by?(gem_version) || Gem::Requirement.new('2.0.19').satisfied_by?(gem_version)
def supports_legacy_tracer?
Gem::Requirement.new('!= 2.0.18').satisfied_by?(gem_version)
end

def supports_new_tracer?
Gem::Requirement.new('>= 2.0.19').satisfied_by?(gem_version)
end

## Supported configuration keys for the install config hash:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module OpenTelemetry
module Instrumentation
module GraphQL
VERSION = '0.26.3'
VERSION = '0.26.4'
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# SPDX-License-Identifier: Apache-2.0

require 'test_helper'

require 'opentelemetry-test-helpers'
require_relative '../../../lib/opentelemetry/instrumentation/graphql'

describe OpenTelemetry::Instrumentation::GraphQL do
Expand All @@ -27,16 +27,73 @@
end

describe '#install' do
describe 'when a user supplies an invalid schema' do
let(:config) { { schemas: [Old::Truck], legacy_tracing: instrumentation.legacy_tracing_requirement_satisfied? } }

it 'fails gracefully and logs the error' do
mock_logger = Minitest::Mock.new
mock_logger.expect(:error, nil, [String])
OpenTelemetry.stub :logger, mock_logger do
instrumentation.install(config)
describe 'when legacy_tracing is disabled' do
let(:config) { { schemas: [SomeGraphQLAppSchema], legacy_tracing: false } }

it 'installs the GraphQLTrace instrumentation using the latest api' do
skip unless instrumentation.supports_new_tracer?

expected_tracer = OpenTelemetry::Instrumentation::GraphQL::Tracers::GraphQLTrace
instrumentation.install(config)
_(SomeGraphQLAppSchema.trace_class.ancestors).must_include(expected_tracer)
end

it 'does not install on incompatible versions of GraphQL' do
skip if instrumentation.supports_new_tracer?

instrumentation.install(config)
_(instrumentation.installed?).must_equal(false)
end

describe 'when a user supplies an invalid schema' do
let(:config) { { schemas: [Old::Truck], legacy_tracing: false } }

it 'fails gracefully and logs the error' do
skip unless instrumentation.supports_new_tracer?

OpenTelemetry::TestHelpers.with_test_logger do |log|
instrumentation.install(config)
_(log.string).must_match(
/ Unable to patch schema Old::Truck: undefined method `trace_with' for Old::Truck:Class/
)
end
end
end
end

describe 'when legacy_tracing is enabled' do
let(:config) { { schemas: [SomeGraphQLAppSchema], legacy_tracing: true } }

it 'installs the GraphQLTracer instrumentation using legacy api' do
skip unless instrumentation.supports_legacy_tracer?

expected_tracer = OpenTelemetry::Instrumentation::GraphQL::Tracers::GraphQLTracer
instrumentation.install(config)
_(instrumentation.installed?).must_equal(true)
_(SomeGraphQLAppSchema.tracers[0].class).must_equal(expected_tracer)
end

it 'does not install instrumentation on gem versions that do not support it' do
skip if instrumentation.supports_legacy_tracer?

instrumentation.install(config)
_(instrumentation.installed?).must_equal(false)
end

describe 'when a user supplies an invalid schema' do
let(:config) { { schemas: [Old::Truck], legacy_tracing: true } }

it 'fails gracefully and logs the error' do
skip unless instrumentation.supports_legacy_tracer?

OpenTelemetry::TestHelpers.with_test_logger do |log|
instrumentation.install(config)

_(log.string).must_match(
/Unable to patch schema Old::Truck: undefined method `use' for Old::Truck:Class/
)
end
end
mock_logger.verify
end
end
end
Expand Down
Loading

0 comments on commit 4805d8f

Please sign in to comment.