public String getAppList(){ return ExtraFieldPropagation.get(TX_APP_LIST); }
/** * Returns a mapping of fields in the current trace context, or empty if there are none. * * <p>Prefer {@link #set(TraceContext, String, String)} if you have a reference to a span. */ public static Map<String, String> getAll() { TraceContext context = currentTraceContext(); if (context == null) return Collections.emptyMap(); return getAll(context); }
/** * Sets the current value of the field with the specified key, or drops if not a configured * field. * * <p>Prefer {@link #set(TraceContext, String, String)} if you have a reference to a span. */ public static void set(String name, String value) { TraceContext context = currentTraceContext(); if (context != null) set(context, name, value); }
/** * Returns the value of the field with the specified key or null if not available. * * <p>Prefer {@link #get(TraceContext, String)} if you have a reference to a span. */ @Nullable public static String get(String name) { TraceContext context = currentTraceContext(); return context != null ? get(context, name) : null; }
protected Tracing.Builder tracingBuilder(Sampler sampler) { return Tracing.newBuilder() .spanReporter(s -> { // make sure the context was cleared prior to finish.. no leaks! TraceContext current = httpTracing.tracing().currentTraceContext().get(); boolean contextLeak = false; if (current != null) { // add annotation in addition to throwing, in case we are off the main thread if (current.spanIdString().equals(s.id())) { s = s.toBuilder().addAnnotation(s.timestampAsLong(), CONTEXT_LEAK).build(); contextLeak = true; } } spans.add(s); // throw so that we can see the path to the code that leaked the context if (contextLeak) { throw new AssertionError(CONTEXT_LEAK + " on " + Thread.currentThread().getName()); } }) .propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, EXTRA_KEY)) .currentTraceContext(currentTraceContext) .sampler(sampler); } }
@Override public Set<Object> getSingletons() { return new LinkedHashSet<>(asList(new Resource(), TracingApplicationEventListener.create( HttpTracing.create(Tracing.newBuilder() .propagationFactory(ExtraFieldPropagation.newFactoryBuilder(B3Propagation.FACTORY) .addField("x-vcap-request-id") .addPrefixedFields("baggage-", asList("country-code", "user-id")) .build() ) .spanReporter(Reporter.NOOP) .build()) ))); } }
/** Returns a mapping of any fields in the extraction result. */ public static Map<String, String> getAll(TraceContextOrSamplingFlags extracted) { if (extracted == null) throw new NullPointerException("extracted == null"); TraceContext extractedContext = extracted.context(); if (extractedContext != null) return getAll(extractedContext); PropagationFields fields = TraceContext.findExtra(Extra.class, extracted.extra()); return fields != null ? fields.toMap() : Collections.emptyMap(); }
@Override public final <K> ExtraFieldPropagation<K> create(Propagation.KeyFactory<K> keyFactory) { int length = keyNames.length; List<K> keys = new ArrayList<>(length); for (int i = 0; i < length; i++) { keys.add(keyFactory.create(keyNames[i])); } return new ExtraFieldPropagation<>(this, keyFactory, keys); }
@Setup(Level.Trial) public void init() { tracer = Tracing.newBuilder() .addFinishedSpanHandler(new FinishedSpanHandler() { @Override public boolean handle(TraceContext context, MutableSpan span) { return true; // anonymous subtype prevents all recording from being no-op } }) .spanReporter(Reporter.NOOP).build().tracer(); tracerExtra = Tracing.newBuilder() .propagationFactory(ExtraFieldPropagation.newFactory( B3Propagation.FACTORY, "x-vcap-request-id")) .addFinishedSpanHandler(new FinishedSpanHandler() { @Override public boolean handle(TraceContext context, MutableSpan span) { return true; // anonymous subtype prevents all recording from being no-op } }) .spanReporter(Reporter.NOOP).build().tracer(); }
/** * Returns the value of the field with the specified key or null if not available. * * <p>Prefer {@link #get(TraceContext, String)} if you have a reference to a span. */ @Nullable public static String get(String name) { TraceContext context = currentTraceContext(); return context != null ? get(context, name) : null; }
/** * Sets the current value of the field with the specified key, or drops if not a configured * field. * * <p>Prefer {@link #set(TraceContext, String, String)} if you have a reference to a span. */ public static void set(String name, String value) { TraceContext context = currentTraceContext(); if (context != null) set(context, name, value); }
@Bean @ConditionalOnMissingBean Propagation.Factory sleuthPropagation(SleuthProperties sleuthProperties) { if (sleuthProperties.getBaggageKeys().isEmpty() && sleuthProperties.getPropagationKeys().isEmpty()) { return B3Propagation.FACTORY; } ExtraFieldPropagation.FactoryBuilder factoryBuilder; if (this.extraFieldPropagationFactoryBuilder != null) { factoryBuilder = this.extraFieldPropagationFactoryBuilder; } else { factoryBuilder = ExtraFieldPropagation .newFactoryBuilder(B3Propagation.FACTORY); } if (!sleuthProperties.getBaggageKeys().isEmpty()) { factoryBuilder = factoryBuilder // for HTTP .addPrefixedFields("baggage-", sleuthProperties.getBaggageKeys()) // for messaging .addPrefixedFields("baggage_", sleuthProperties.getBaggageKeys()); } if (!sleuthProperties.getPropagationKeys().isEmpty()) { for (String key : sleuthProperties.getPropagationKeys()) { factoryBuilder = factoryBuilder.addField(key); } } return factoryBuilder.build(); }
/** Returns empty unless {@link ExtraFieldPropagation} is in use */ @Override public Iterable<Map.Entry<String, String>> baggageItems() { return ExtraFieldPropagation.getAll(extractionResult).entrySet(); } }
@Override public final <K> ExtraFieldPropagation<K> create(Propagation.KeyFactory<K> keyFactory) { int length = keyNames.length; List<K> keys = new ArrayList<>(length); for (int i = 0; i < length; i++) { keys.add(keyFactory.create(keyNames[i])); } return new ExtraFieldPropagation<>(this, keyFactory, keys); }
public String getGroupId() { return ExtraFieldPropagation.get(GROUP_ID_FIELD_NAME); }
public void createManagerKey(String managerKey) { ExtraFieldPropagation.set(TX_MANAGER_FIELD_NAME, managerKey); }
/** Controls aspects of tracing such as the service name that shows up in the UI */ @Bean Tracing tracing(@Value("${spring.application.name}") String serviceName) { return Tracing.newBuilder() .localServiceName(serviceName) .propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, "user-name")) .currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder() .addScopeDecorator(MDCScopeDecorator.create()) // puts trace IDs into logs .build() ) .spanReporter(spanReporter()).build(); }
public TracedExtra() { super(TracingFilter.create(Tracing.newBuilder() .propagationFactory(ExtraFieldPropagation.newFactoryBuilder(B3Propagation.FACTORY) .addField("x-vcap-request-id") .addPrefixedFields("baggage-", Arrays.asList("country-code", "user-id")) .build() ) .spanReporter(Reporter.NOOP) .build())); } }
/** * Returns a mapping of fields in the current trace context, or empty if there are none. * * <p>Prefer {@link #set(TraceContext, String, String)} if you have a reference to a span. */ public static Map<String, String> getAll() { TraceContext context = currentTraceContext(); if (context == null) return Collections.emptyMap(); return getAll(context); }