|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.instrumentation.api.incubator.instrumenter; |
| 7 | + |
| 8 | +import io.opentelemetry.api.logs.LogRecordBuilder; |
| 9 | +import io.opentelemetry.api.logs.Severity; |
| 10 | +import io.opentelemetry.context.Context; |
| 11 | +import io.opentelemetry.instrumentation.api.internal.InternalExceptionEventExtractor; |
| 12 | + |
| 13 | +/** |
| 14 | + * Extractor that populates the exception event {@link LogRecordBuilder} for a request. This allows |
| 15 | + * instrumentations to set the event name, severity, and any additional attributes on the exception |
| 16 | + * log event. |
| 17 | + * |
| 18 | + * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change |
| 19 | + * at any time. |
| 20 | + */ |
| 21 | +@FunctionalInterface |
| 22 | +public interface ExceptionEventExtractor<REQUEST> extends InternalExceptionEventExtractor<REQUEST> { |
| 23 | + |
| 24 | + /** |
| 25 | + * Returns an {@link ExceptionEventExtractor} that always sets the given event name and severity. |
| 26 | + */ |
| 27 | + static <REQUEST> ExceptionEventExtractor<REQUEST> create(String eventName, Severity severity) { |
| 28 | + return (logRecordBuilder, context, request) -> { |
| 29 | + logRecordBuilder.setEventName(eventName); |
| 30 | + logRecordBuilder.setSeverity(severity); |
| 31 | + }; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Returns an {@link ExceptionEventExtractor} that sets the given event name, with {@link |
| 36 | + * Severity#ERROR} for local root spans and {@link Severity#DEBUG} otherwise. |
| 37 | + */ |
| 38 | + static <REQUEST> ExceptionEventExtractor<REQUEST> create(String eventName) { |
| 39 | + return DefaultExceptionEventExtractor.create(eventName); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Populates the exception event {@link LogRecordBuilder} with the event name, severity, and any |
| 44 | + * additional attributes for the given context and request. |
| 45 | + */ |
| 46 | + @Override |
| 47 | + void extract(LogRecordBuilder logRecordBuilder, Context context, REQUEST request); |
| 48 | +} |
0 commit comments