Skip to content

Commit 2433671

Browse files
committed
fix: patch dataloader to propagate context to new fiber
1 parent 44337aa commit 2433671

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

instrumentation/graphql/lib/opentelemetry/instrumentation/graphql/instrumentation.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
2727
require_relative 'tracers/graphql_trace'
2828
install_new_tracer(config)
2929
end
30+
31+
patch
3032
end
3133

3234
present do
@@ -96,6 +98,13 @@ def install_new_tracer(config = {})
9698
end
9799
end
98100
end
101+
102+
def patch
103+
return if gem_version < Gem::Version.new('2.1.8')
104+
105+
require_relative 'patches/dataloader'
106+
::GraphQL::Dataloader.prepend(Patches::Dataloader)
107+
end
99108
end
100109
end
101110
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright The OpenTelemetry Authors
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
module OpenTelemetry
8+
module Instrumentation
9+
module GraphQL
10+
module Patches
11+
# Patches GraphQL::Dataloader to propagate context to new fiber
12+
module Dataloader
13+
def spawn_fiber(&block)
14+
ctx = OpenTelemetry::Context.current
15+
super do
16+
OpenTelemetry::Context.with_current(ctx, &block)
17+
end
18+
end
19+
end
20+
end
21+
end
22+
end
23+
end

0 commit comments

Comments
 (0)