This repository was archived by the owner on Apr 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathBuiltInMetricsTracerFactory.java
More file actions
69 lines (63 loc) · 2.55 KB
/
Copy pathBuiltInMetricsTracerFactory.java
File metadata and controls
69 lines (63 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner;
import com.google.api.gax.tracing.ApiTracer;
import com.google.api.gax.tracing.ApiTracerFactory;
import com.google.api.gax.tracing.MethodName;
import com.google.api.gax.tracing.MetricsTracer;
import com.google.api.gax.tracing.MetricsTracerFactory;
import com.google.api.gax.tracing.SpanName;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
/**
* A {@link ApiTracerFactory} to build instances of {@link MetricsTracer}.
*
* <p>This class extends the {@link MetricsTracerFactory} which wraps the {@link
* BuiltInMetricsRecorder} and pass it to {@link BuiltInMetricsTracer}. It will be * used to record
* metrics in {@link BuiltInMetricsTracer}.
*
* <p>This class is expected to be initialized once during client initialization.
*/
class BuiltInMetricsTracerFactory extends MetricsTracerFactory {
protected BuiltInMetricsRecorder builtInMetricsRecorder;
private final Map<String, String> attributes;
private final TraceWrapper traceWrapper;
/**
* Pass in a Map of client level attributes which will be added to every single MetricsTracer
* created from the ApiTracerFactory.
*/
public BuiltInMetricsTracerFactory(
BuiltInMetricsRecorder builtInMetricsRecorder,
Map<String, String> attributes,
TraceWrapper traceWrapper) {
super(builtInMetricsRecorder, attributes);
this.builtInMetricsRecorder = builtInMetricsRecorder;
this.attributes = ImmutableMap.copyOf(attributes);
this.traceWrapper = traceWrapper;
}
@Override
public ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType operationType) {
ISpan currentSpan = this.traceWrapper.getCurrentSpan();
BuiltInMetricsTracer metricsTracer =
new BuiltInMetricsTracer(
MethodName.of(spanName.getClientName(), spanName.getMethodName()),
builtInMetricsRecorder,
this.traceWrapper,
currentSpan);
metricsTracer.addAttributes(attributes);
return metricsTracer;
}
}