1
1
/*
2
- * Copyright 2023 Google
2
+ * Copyright 2022 Google
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
15
15
*/
16
16
package com .google .cloud .opentelemetry .trace ;
17
17
18
+ import static com .google .api .client .util .Preconditions .checkNotNull ;
19
+
18
20
import com .google .api .gax .core .FixedCredentialsProvider ;
19
21
import com .google .api .gax .core .NoCredentialsProvider ;
20
22
import com .google .api .gax .grpc .GrpcTransportChannel ;
33
35
import io .opentelemetry .sdk .common .CompletableResultCode ;
34
36
import io .opentelemetry .sdk .trace .data .SpanData ;
35
37
import io .opentelemetry .sdk .trace .export .SpanExporter ;
36
-
37
38
import java .io .IOException ;
38
39
import java .util .ArrayList ;
39
40
import java .util .Collection ;
40
41
import java .util .List ;
41
42
import java .util .Map ;
42
-
43
- import static com .google .api .client .util .Preconditions .checkNotNull ;
43
+ import javax .annotation .Nonnull ;
44
44
45
45
class InternalTraceExporter implements SpanExporter {
46
46
@@ -53,6 +53,15 @@ class InternalTraceExporter implements SpanExporter {
53
53
Map .of ("User-Agent" , "opentelemetry-operations-java/" + TraceVersions .EXPORTER_VERSION );
54
54
private static final HeaderProvider HEADER_PROVIDER = () -> HEADERS ;
55
55
56
+ private static InternalTraceExporter createWithClient (
57
+ String projectId ,
58
+ CloudTraceClient cloudTraceClient ,
59
+ ImmutableMap <String , String > attributeMappings ,
60
+ Map <String , AttributeValue > fixedAttributes ) {
61
+ return new InternalTraceExporter (
62
+ projectId , cloudTraceClient , attributeMappings , fixedAttributes );
63
+ }
64
+
56
65
static SpanExporter createWithConfiguration (TraceConfiguration configuration ) throws IOException {
57
66
String projectId = configuration .getProjectId ();
58
67
TraceServiceStub stub = configuration .getTraceServiceStub ();
@@ -99,13 +108,34 @@ static SpanExporter createWithConfiguration(TraceConfiguration configuration) th
99
108
configuration .getFixedAttributes ());
100
109
}
101
110
102
- private static InternalTraceExporter createWithClient (
103
- String projectId ,
104
- CloudTraceClient cloudTraceClient ,
105
- ImmutableMap <String , String > attributeMappings ,
106
- Map <String , AttributeValue > fixedAttributes ) {
107
- return new InternalTraceExporter (
108
- projectId , cloudTraceClient , attributeMappings , fixedAttributes );
111
+ /**
112
+ * A noop implementation of {@link TraceExporter}. Should be used when {@link TraceExporter}
113
+ * cannot be initialized due to some error/exception.
114
+ *
115
+ * @return noop implementation of {@link TraceExporter} as a {@link SpanExporter}.
116
+ */
117
+ static SpanExporter noop () {
118
+ return new SpanExporter () {
119
+ @ Override
120
+ public CompletableResultCode export (@ Nonnull Collection <SpanData > spans ) {
121
+ return CompletableResultCode .ofSuccess ();
122
+ }
123
+
124
+ @ Override
125
+ public CompletableResultCode flush () {
126
+ return CompletableResultCode .ofSuccess ();
127
+ }
128
+
129
+ @ Override
130
+ public CompletableResultCode shutdown () {
131
+ return CompletableResultCode .ofSuccess ();
132
+ }
133
+
134
+ @ Override
135
+ public String toString () {
136
+ return "NoopTraceExporter{}" ;
137
+ }
138
+ };
109
139
}
110
140
111
141
InternalTraceExporter (
0 commit comments