@Test public void happyPath() { when(propagator.extract(carrier)).thenReturn(context); tracer.registerPropagator(Format.Builtin.TEXT_MAP, propagator); SpanContext extracted = tracer.extract(Format.Builtin.TEXT_MAP, carrier); assertThat(extracted, is((SpanContext) context)); verify(propagator).extract(carrier); verifyNoMoreInteractions(propagator); }
@Test public void happyPath() { tracer.registerPropagator(Format.Builtin.TEXT_MAP, propagator); tracer.inject(context, Format.Builtin.TEXT_MAP, carrier); verify(propagator).inject(context, carrier); verifyNoMoreInteractions(propagator); }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public <C> void inject(SpanContext spanContext, Format<C> format, C carrier) { if ((format == null) || (carrier == null)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Context can not be injected, both format and carrier must be provided."); } return; } if (spanContext instanceof SpanContextImpl) { Propagator<C> propagator = (Propagator<C>) propagators.get(format); if (null != propagator) { propagator.inject((SpanContextImpl) spanContext, carrier); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Context can not be injected, propagator does not exists for the format " + format.toString() + "."); } } } }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public <C> SpanContext extract(Format<C> format, C carrier) { if ((format == null) || (carrier == null)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Context can not be extracted, both format and carrier must be provided."); } return null; } Propagator<C> propagator = (Propagator<C>) propagators.get(format); if (null != propagator) { SpanContextImpl context = propagator.extract(carrier); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Context extracted: " + context); } return context; } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Context can not be extracted, propagator does not exists for the format " + format.toString() + "."); } return null; } }