|
1 | 1 | #include <ruby.h>
|
2 | 2 |
|
| 3 | +#include "datadog_ruby_common.h" |
3 | 4 | #include "collectors_thread_context.h"
|
4 | 5 | #include "clock_id.h"
|
5 | 6 | #include "collectors_stack.h"
|
@@ -1688,35 +1689,41 @@ static VALUE _native_sample_skipped_allocation_samples(DDTRACE_UNUSED VALUE self
|
1688 | 1689 | return Qtrue;
|
1689 | 1690 | }
|
1690 | 1691 |
|
1691 |
| -static VALUE otel_context_storage_for(thread_context_collector_state *state, VALUE thread) { |
1692 |
| - if (state->otel_context_source == OTEL_CONTEXT_SOURCE_FIBER_IVAR) { // otel-api 1.5+ |
1693 |
| - VALUE current_fiber = current_fiber_for(thread); |
1694 |
| - return current_fiber == Qnil ? Qnil : rb_ivar_get(current_fiber, otel_fiber_context_storage_id /* @opentelemetry_context */); |
1695 |
| - } |
1696 |
| - |
1697 |
| - if (state->otel_context_source == OTEL_CONTEXT_SOURCE_FIBER_LOCAL) { // otel-api < 1.5 |
1698 |
| - return rb_thread_local_aref(thread, otel_context_storage_id /* __opentelemetry_context_storage__ */); |
1699 |
| - } |
| 1692 | +#ifndef NO_CURRENT_FIBER_FOR // Ruby 3.1+ |
| 1693 | + static VALUE otel_context_storage_for(thread_context_collector_state *state, VALUE thread) { |
| 1694 | + if (state->otel_context_source == OTEL_CONTEXT_SOURCE_FIBER_IVAR) { // otel-api 1.5+ |
| 1695 | + VALUE current_fiber = current_fiber_for(thread); |
| 1696 | + return current_fiber == Qnil ? Qnil : rb_ivar_get(current_fiber, otel_fiber_context_storage_id /* @opentelemetry_context */); |
| 1697 | + } |
1700 | 1698 |
|
1701 |
| - // If we got here, it means we never observed a context being set. Let's probe which one to use. |
1702 |
| - VALUE current_fiber = current_fiber_for(thread); |
1703 |
| - if (current_fiber != Qnil) { |
1704 |
| - VALUE context_storage = rb_ivar_get(current_fiber, otel_fiber_context_storage_id /* @opentelemetry_context */); |
1705 |
| - if (context_storage != Qnil) { |
1706 |
| - state->otel_context_source = OTEL_CONTEXT_SOURCE_FIBER_IVAR; // Remember for next time |
1707 |
| - return context_storage; |
| 1699 | + if (state->otel_context_source == OTEL_CONTEXT_SOURCE_FIBER_LOCAL) { // otel-api < 1.5 |
| 1700 | + return rb_thread_local_aref(thread, otel_context_storage_id /* __opentelemetry_context_storage__ */); |
1708 | 1701 | }
|
1709 |
| - } else { |
1710 |
| - VALUE context_storage = rb_thread_local_aref(thread, otel_context_storage_id /* __opentelemetry_context_storage__ */); |
1711 |
| - if (context_storage != Qnil) { |
1712 |
| - state->otel_context_source = OTEL_CONTEXT_SOURCE_FIBER_LOCAL; // Remember for next time |
1713 |
| - return context_storage; |
| 1702 | + |
| 1703 | + // If we got here, it means we never observed a context being set. Let's probe which one to use. |
| 1704 | + VALUE current_fiber = current_fiber_for(thread); |
| 1705 | + if (current_fiber != Qnil) { |
| 1706 | + VALUE context_storage = rb_ivar_get(current_fiber, otel_fiber_context_storage_id /* @opentelemetry_context */); |
| 1707 | + if (context_storage != Qnil) { |
| 1708 | + state->otel_context_source = OTEL_CONTEXT_SOURCE_FIBER_IVAR; // Remember for next time |
| 1709 | + return context_storage; |
| 1710 | + } |
| 1711 | + } else { |
| 1712 | + VALUE context_storage = rb_thread_local_aref(thread, otel_context_storage_id /* __opentelemetry_context_storage__ */); |
| 1713 | + if (context_storage != Qnil) { |
| 1714 | + state->otel_context_source = OTEL_CONTEXT_SOURCE_FIBER_LOCAL; // Remember for next time |
| 1715 | + return context_storage; |
| 1716 | + } |
1714 | 1717 | }
|
1715 |
| - } |
1716 | 1718 |
|
1717 |
| - // There's no context storage attached to the current thread |
1718 |
| - return Qnil; |
1719 |
| -} |
| 1719 | + // There's no context storage attached to the current thread |
| 1720 | + return Qnil; |
| 1721 | + } |
| 1722 | +#else |
| 1723 | + static inline VALUE otel_context_storage_for(DDTRACE_UNUSED thread_context_collector_state *state, VALUE thread) { |
| 1724 | + return rb_thread_local_aref(thread, otel_context_storage_id /* __opentelemetry_context_storage__ */); |
| 1725 | + } |
| 1726 | +#endif |
1720 | 1727 |
|
1721 | 1728 | // This method differs from trace_identifiers_for/ddtrace_otel_trace_identifiers_for to support the situation where
|
1722 | 1729 | // the opentelemetry ruby library is being used for tracing AND the ddtrace tracing bits are not involved at all.
|
|
0 commit comments