@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { ((brave.SpanCustomizer) request.getAttribute("brave.SpanCustomizer")).tag("foo", "bar"); chain.doFilter(request, response); }
@Override public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) { customizer.tag("http.url", adapter.url(req)); // just the path is logged by default customizer.tag("context.visible", String.valueOf(currentTraceContext.get() != null)); customizer.tag("request_customizer.is_span", (customizer instanceof brave.Span) + ""); }
@Override public <Resp> void response(HttpAdapter<?, Resp> adapter, Resp res, Throwable error, SpanCustomizer customizer) { super.response(adapter, res, error, customizer); customizer.tag("response_customizer.is_span", (customizer instanceof brave.Span) + ""); } }).build();
/** * Invoked prior to request invocation during {@link ContainerRequestFilter#filter(ContainerRequestContext)} * where the resource info was injected from context. * * <p>Adds the tags {@link #RESOURCE_CLASS} and {@link #RESOURCE_METHOD}. Override or use {@link #NOOP} * to change this behavior. */ protected void resourceInfo(ResourceInfo resourceInfo, SpanCustomizer customizer) { customizer.tag(RESOURCE_CLASS, resourceInfo.getResourceClass().getSimpleName()); customizer.tag(RESOURCE_METHOD, resourceInfo.getResourceMethod().getName()); }
void tagQueueOrTopic(Destination destination, SpanCustomizer span) { try { if (destination instanceof Queue) { span.tag(JMS_QUEUE, ((Queue) destination).getQueueName()); } else if (destination instanceof Topic) { span.tag(JMS_TOPIC, ((Topic) destination).getTopicName()); } } catch (JMSException ignored) { // don't crash on wonky exceptions! } } }
@Override public <Resp> void response(HttpAdapter<?, Resp> adapter, Resp res, Throwable error, SpanCustomizer customizer) { super.response(adapter, res, error, customizer); customizer.tag("response_customizer.is_span", (customizer instanceof brave.Span) + ""); } })
/** * Override to change what data from the status or trailers are parsed into the span modeling it. * By default, this tags "grpc.status_code" and "error" when it is not OK. */ protected void onClose(Status status, Metadata trailers, SpanCustomizer span) { if (status != null && status.getCode() != Status.Code.OK) { String code = String.valueOf(status.getCode()); span.tag("grpc.status_code", code); span.tag("error", code); } } }
/** * When an upstream context was not present, lookup keys are unlikely added */ void addTags(Message<?> message, SpanCustomizer result, MessageChannel channel) { // TODO topic etc if (channel != null) { result.tag("channel", messageChannelName(channel)); } }
/** {@inheritDoc} */ @Override public SpanCustomizer tag(String key, String value) { return tracer.currentSpanCustomizer().tag(key, value); }
/** * Invoked prior to request invocation during {@link HandlerInterceptor#preHandle(HttpServletRequest, HttpServletResponse, Object)}. * * <p>Adds the tags {@link #CONTROLLER_CLASS} and {@link #CONTROLLER_METHOD}. Override or use * {@link #NOOP} to change this behavior. */ protected void preHandle(HttpServletRequest request, Object handler, SpanCustomizer customizer) { if (WebMvcRuntime.get().isHandlerMethod(handler)) { HandlerMethod handlerMethod = ((HandlerMethod) handler); customizer.tag(CONTROLLER_CLASS, handlerMethod.getBeanType().getSimpleName()); customizer.tag(CONTROLLER_METHOD, handlerMethod.getMethod().getName()); } else { customizer.tag(CONTROLLER_CLASS, handler.getClass().getSimpleName()); } }
@Override public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) { customizer.name(adapter.method(req).toLowerCase() + " " + adapter.path(req)); customizer.tag("http.url", adapter.url(req)); // just the path is logged by default customizer.tag("context.visible", String.valueOf(currentTraceContext.get() != null)); customizer.tag("request_customizer.is_span", (customizer instanceof brave.Span) + ""); }
/** When an upstream context was not present, lookup keys are unlikely added */ static void addTags(ConsumerRecord<?, ?> record, SpanCustomizer result) { if (record.key() instanceof String && !"".equals(record.key())) { result.tag(KafkaTags.KAFKA_KEY_TAG, record.key().toString()); } result.tag(KafkaTags.KAFKA_TOPIC_TAG, record.topic()); } }
@Override public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) { super.request(adapter, req, customizer); customizer.tag("http.url", adapter.url(req)); // just the path is logged by default } };
/** Same behaviour as {@link brave.SpanCustomizer#tag(String, String)} */ protected final void tag(Object span, String key, String message) { if (span instanceof SpanCustomizer) { ((SpanCustomizer) span).tag(key, message); } else if (span instanceof ScopedSpan) { ((ScopedSpan) span).tag(key, message); } else if (span instanceof MutableSpan) { ((MutableSpan) span).tag(key, message); } } }
/** * Invoked prior to request invocation during {@link RequestEventListener#onEvent(RequestEvent)} * where the event type is {@link RequestEvent.Type#REQUEST_MATCHED} * * <p>Adds the tags {@link #RESOURCE_CLASS} and {@link #RESOURCE_METHOD}. Override or use {@link #NOOP} * to change this behavior. */ protected void requestMatched(RequestEvent event, SpanCustomizer customizer) { Invocable i = event.getContainerRequest().getUriInfo().getMatchedResourceMethod().getInvocable(); customizer.tag(RESOURCE_CLASS, i.getHandler().getHandlerClass().getSimpleName()); customizer.tag(RESOURCE_METHOD, i.getHandlingMethod().getName()); }
private void addAnnotatedArguments(List<SleuthAnnotatedParameter> toBeAdded) { for (SleuthAnnotatedParameter container : toBeAdded) { String tagValue = resolveTagValue(container.annotation, container.argument); String tagKey = resolveTagKey(container); span().tag(tagKey, tagValue); } }
@Override public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) { super.request(adapter, req, customizer); String url = adapter.url(req); URI uri = URI.create(url); addRequestTags(customizer, url, uri.getHost(), uri.getPath(), adapter.method(req)); this.traceKeys.getHttp().getHeaders().forEach(((s) -> { String headerValue = adapter.requestHeader(req, s); if (headerValue != null) { customizer.tag(key(s), headerValue); } })); }
/** * Override to change what data from the http error are parsed into the span modeling it. By * default, this tags "error" as the exception or the status code if it is neither 2xx nor 3xx. * * <p>Note: Either the httpStatus or error parameters may be null, but not both * * <p>Conventionally associated with the tag key "error" */ // BRAVE6: httpStatus is a Integer, not a int. We can't change this api as users expect this to be // called by default. Unfortunately, this implies boxing until we can change it. protected void error(@Nullable Integer httpStatus, @Nullable Throwable error, SpanCustomizer customizer) { if (error != null) { errorParser().error(error, customizer); } else if (httpStatus != null) { String maybeErrorStatus = maybeStatusAsString(httpStatus, 399); if (maybeErrorStatus != null) customizer.tag("error", maybeErrorStatus); } }