You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(zio-opentelemetry): refactor logging configuration for extensibility
Refactor the `Logging` trait to allow overriding the log level and
log endpoint via protected methods (`oltpLogLevel` and `otelLogEndpoint`)
instead of directly accessing environment variables. This enables
easier customization in subclasses.
Copy file name to clipboardExpand all lines: observability/zio-opentelemetry/src/main/scala/sttp/tapir/server/ziopentelemetry/Logger.scala
+18-3Lines changed: 18 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -16,11 +16,17 @@ trait Logging {
16
16
17
17
/** The log level to use for the OpenTelemetry logger provider.
18
18
*
19
-
* Uses the `OTEL_LOG_LEVEL` environment variable to determine the log level.
19
+
* Uses the [[oltpLogLevel]] method to determine the log level, can be overridden to provide a different log level logic.
20
20
*
21
21
* By default, this is set to `INFO`. You can override this to change the log level, e.g. to `DEBUG` for more verbose logging.
22
22
*/
23
-
deflogLevel= sys.env.getOrElse("OTEL_LOG_LEVEL", "INFO") match {
23
+
deflogLevel= oltpLogLevel
24
+
25
+
/** Uses the `OTEL_LOG_LEVEL` environment variable to determine the log level.
26
+
*
27
+
* By default, this is set to `INFO`. You can override this to change the log level, e.g. to `DEBUG` for more verbose logging.
28
+
*/
29
+
finalprotecteddefoltpLogLevel= sys.env.getOrElse("OTEL_LOG_LEVEL", "INFO").toUpperCase match {
24
30
case"DEBUG"=>LogLevel.Debug
25
31
case"INFO"=>LogLevel.Info
26
32
case"WARN"=>LogLevel.Warning
@@ -30,14 +36,23 @@ trait Logging {
30
36
case _ =>LogLevel.Info
31
37
}
32
38
39
+
/** The OTLP endpoint to use for logging.
40
+
*
41
+
* Default uses the `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` environment variable to determine the endpoint. If not set, it will use the
42
+
* `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable. If neither is set, it will return `None`.
43
+
*
44
+
* @return
45
+
*/
46
+
deflogEndpoint= otelLogEndpoint
47
+
33
48
/** The OTLP endpoint to use for logging.
34
49
*
35
50
* Uses the `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` environment variable to determine the endpoint. If not set, it will use the
36
51
* `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable. If neither is set, it will return `None`.
37
52
*
38
53
* @return
39
54
*/
40
-
deflogEndpoint:ZIO[Any, Nothing, Option[String]] =OtlpEndpoint("OTEL_EXPORTER_OTLP_LOGS_ENDPOINT") match {
55
+
finalprotecteddefotelLogEndpoint:ZIO[Any, Nothing, Option[String]] =OtlpEndpoint("OTEL_EXPORTER_OTLP_LOGS_ENDPOINT") match {
41
56
caseNone=>
42
57
ZIO.logInfo(
43
58
"No OTLP logs endpoint configured, skipping OpenTelemetry logging setup. To enable it, set either OTEL_EXPORTER_OTLP_LOGS_ENDPOINT or OTEL_EXPORTER_OTLP_ENDPOINT environment variable."
Copy file name to clipboardExpand all lines: observability/zio-opentelemetry/src/main/scala/sttp/tapir/server/ziopentelemetry/ZIOpenTelemetryTracing.scala
0 commit comments