@@ -44,6 +44,8 @@ public class SeleniumSpanExporter {
44
44
private static final ImmutableSet <String > EXCEPTION_ATTRIBUTES =
45
45
ImmutableSet .of ("exception.message" , "exception.stacktrace" );
46
46
private static final boolean httpLogs = OpenTelemetryTracer .getHttpLogs ();
47
+ private static final AttributeKey <String > KEY_SPAN_KIND =
48
+ AttributeKey .stringKey (org .openqa .selenium .remote .tracing .AttributeKey .SPAN_KIND .getKey ());
47
49
48
50
private static String getJsonString (Map <String , Object > map ) {
49
51
StringBuilder text = new StringBuilder ();
@@ -61,13 +63,18 @@ public static SpanProcessor getSpanProcessor() {
61
63
public CompletableResultCode export (Collection <SpanData > spans ) {
62
64
spans .forEach (
63
65
span -> {
64
- LOG .fine (String .valueOf (span ));
65
-
66
- String traceId = span .getTraceId ();
67
- List <EventData > eventList = span .getEvents ();
66
+ if (LOG .isLoggable (Level .FINE )) {
67
+ LOG .fine (String .valueOf (span ));
68
+ }
68
69
69
70
Level logLevel = getLogLevel (span );
70
71
72
+ if (!LOG .isLoggable (logLevel )) {
73
+ return ;
74
+ }
75
+
76
+ String traceId = span .getTraceId ();
77
+ List <EventData > eventList = span .getEvents ();
71
78
eventList .forEach (
72
79
event -> {
73
80
Map <String , Object > map = new HashMap <>();
@@ -111,17 +118,12 @@ public CompletableResultCode shutdown() {
111
118
private static Level getLogLevel (SpanData span ) {
112
119
Level level = Level .FINE ;
113
120
114
- Optional <String > kind =
115
- Optional .ofNullable (
116
- span .getAttributes ()
117
- .get (
118
- AttributeKey .stringKey (
119
- org .openqa .selenium .remote .tracing .AttributeKey .SPAN_KIND .getKey ())));
120
-
121
121
if (span .getStatus ().getStatusCode () == StatusCode .ERROR ) {
122
122
level = Level .WARNING ;
123
- } else {
124
- if (httpLogs && kind .isPresent ()) {
123
+ } else if (httpLogs ) {
124
+ Optional <String > kind = Optional .ofNullable (span .getAttributes ().get (KEY_SPAN_KIND ));
125
+
126
+ if (kind .isPresent ()) {
125
127
String kindValue = kind .get ();
126
128
if (Span .Kind .SERVER .name ().equalsIgnoreCase (kindValue )
127
129
|| Span .Kind .CLIENT .name ().equalsIgnoreCase (kindValue )) {
0 commit comments