|
16 | 16 | * [Sampler](#sampler) |
17 | 17 | * [Span Processor](#span-processor) |
18 | 18 | * [Exporter](#exporter) |
| 19 | +- [Logging And Error Handling](#logging-and-error-handling) |
| 20 | + * [Examples](#examples) |
19 | 21 | <!-- tocstop --> |
20 | 22 |
|
21 | 23 | OpenTelemetry can be used to instrument code for collecting telemetry data. For more details, check |
@@ -409,3 +411,59 @@ tracerProvider.addSpanProcessor(BatchSpanProcessor.newBuilder( |
409 | 411 | [OpenTelemetry Website]: https://opentelemetry.io/ |
410 | 412 | [Obtaining a Tracer]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#obtaining-a-tracer |
411 | 413 | [Semantic Conventions]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions |
| 414 | + |
| 415 | +## Logging and Error Handling |
| 416 | + |
| 417 | +OpenTelemetry uses [java.util.logging](https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html) |
| 418 | +to log information about OpenTelemetry, including errors and warnings about misconfigurations or failures exporting |
| 419 | +data. |
| 420 | + |
| 421 | +By default, log messages are handled by the root handler in your application. If you have not |
| 422 | +installed a custom root handler for your application, logs of level `INFO` or higher are sent to the console by default. |
| 423 | + |
| 424 | +You may |
| 425 | +want to change the behavior of the logger for OpenTelemetry. For example, you can reduce the logging level |
| 426 | +to output additional information when debugging, increase the level for a particular class to ignore errors coming |
| 427 | +from that class, or install a custom handler or filter to run custom code whenever OpenTelemetry logs |
| 428 | +a particular message. |
| 429 | + |
| 430 | +### Examples |
| 431 | + |
| 432 | +```properties |
| 433 | +## Turn off all OpenTelemetry logging |
| 434 | +io.opentelemetry.level = OFF |
| 435 | +``` |
| 436 | + |
| 437 | +```properties |
| 438 | +## Turn off logging for just the BatchSpanProcessor |
| 439 | +io.opentelemetry.sdk.trace.export.BatchSpanProcessor.level = OFF |
| 440 | +``` |
| 441 | + |
| 442 | +```properties |
| 443 | +## Log "FINE" messages for help in debugging |
| 444 | +io.opentelemetry.level = FINE |
| 445 | + |
| 446 | +## Sets the default ConsoleHandler's logger's level |
| 447 | +## Note this impacts the logging outside of OpenTelemetry as well |
| 448 | +java.util.logging.ConsoleHandler.level = FINE |
| 449 | + |
| 450 | +``` |
| 451 | + |
| 452 | +For more fine-grained control and special case handling, custom handlers and filters can be specified |
| 453 | +with code. |
| 454 | + |
| 455 | +```java |
| 456 | +// Custom filter which does not log errors that come from the export |
| 457 | +public class IgnoreExportErrorsFilter implements Filter { |
| 458 | + |
| 459 | + public boolean isLoggable(LogRecord record) { |
| 460 | + return !record.getMessage().contains("Exception thrown by the export"); |
| 461 | + } |
| 462 | +} |
| 463 | +``` |
| 464 | + |
| 465 | +```properties |
| 466 | +## Registering the custom filter on the BatchSpanProcessor |
| 467 | +io.opentelemetry.sdk.trace.export.BatchSpanProcessor = io.opentelemetry.extensions.logging.IgnoreExportErrorsFilter |
| 468 | +``` |
| 469 | + |
0 commit comments