-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: misc otel internalization/cleanup #2835
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,11 @@ | |
|
||
package com.google.cloud.storage.otel; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
import com.google.api.core.ApiFuture; | ||
import com.google.api.gax.core.GaxProperties; | ||
import com.google.cloud.storage.GrpcStorageOptions; | ||
import com.google.cloud.storage.StorageOptions; | ||
import com.google.cloud.storage.otel.OpenTelemetryTraceUtil.Context; | ||
import com.google.cloud.storage.otel.OpenTelemetryTraceUtil.Span; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.Attributes; | ||
|
@@ -42,19 +41,18 @@ class OpenTelemetryInstance implements OpenTelemetryTraceUtil { | |
|
||
private final String transport; | ||
|
||
public OpenTelemetryInstance(StorageOptions storageOptions) { | ||
OpenTelemetryInstance(StorageOptions storageOptions) { | ||
this.storageOptions = storageOptions; | ||
this.openTelemetry = storageOptions.getOpenTelemetrySdk(); | ||
this.tracer = | ||
openTelemetry.getTracer(LIBRARY_NAME, GaxProperties.getLibraryVersion(this.getClass())); | ||
this.tracer = openTelemetry.getTracer(LIBRARY_NAME, storageOptions.getLibraryVersion()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switch to using the logic from storageOptions rather than gax. Our version is more stable to repackaging, and is what is used for headers and such. We will want to keep them in sync. |
||
this.transport = storageOptions instanceof GrpcStorageOptions ? "grpc" : "http"; | ||
} | ||
|
||
static class Span implements OpenTelemetryTraceUtil.Span { | ||
private final io.opentelemetry.api.trace.Span span; | ||
private final String spanName; | ||
|
||
Span(io.opentelemetry.api.trace.Span span, String spanName) { | ||
private Span(io.opentelemetry.api.trace.Span span, String spanName) { | ||
this.span = span; | ||
this.spanName = spanName; | ||
} | ||
|
@@ -129,7 +127,7 @@ public <T> void endAtFuture(ApiFuture<T> futureValue) {} | |
static class Scope implements OpenTelemetryTraceUtil.Scope { | ||
private final io.opentelemetry.context.Scope scope; | ||
|
||
Scope(io.opentelemetry.context.Scope scope) { | ||
private Scope(io.opentelemetry.context.Scope scope) { | ||
this.scope = scope; | ||
} | ||
|
||
|
@@ -142,7 +140,7 @@ public void close() { | |
static class Context implements OpenTelemetryTraceUtil.Context { | ||
private final io.opentelemetry.context.Context context; | ||
|
||
Context(io.opentelemetry.context.Context context) { | ||
private Context(io.opentelemetry.context.Context context) { | ||
this.context = context; | ||
} | ||
|
||
|
@@ -164,13 +162,13 @@ public OpenTelemetryTraceUtil.Span startSpan(String methodName, String module) { | |
@Override | ||
public OpenTelemetryTraceUtil.Span startSpan( | ||
String methodName, String module, OpenTelemetryTraceUtil.Context parent) { | ||
assert (parent instanceof OpenTelemetryInstance.Context); | ||
checkArgument( | ||
parent instanceof OpenTelemetryInstance.Context, | ||
"parent must be an instance of " + OpenTelemetryInstance.Context.class.getName()); | ||
String formatSpanName = String.format("%s/%s", module, methodName); | ||
Context p2 = (Context) parent; | ||
SpanBuilder spanBuilder = | ||
tracer | ||
.spanBuilder(formatSpanName) | ||
.setSpanKind(SpanKind.CLIENT) | ||
.setParent(((OpenTelemetryInstance.Context) parent).context); | ||
tracer.spanBuilder(formatSpanName).setSpanKind(SpanKind.CLIENT).setParent(p2.context); | ||
io.opentelemetry.api.trace.Span span = | ||
addSettingsAttributesToCurrentSpan(spanBuilder).startSpan(); | ||
return new Span(span, formatSpanName); | ||
|
@@ -193,9 +191,9 @@ private SpanBuilder addSettingsAttributesToCurrentSpan(SpanBuilder spanBuilder) | |
spanBuilder = | ||
spanBuilder.setAllAttributes( | ||
Attributes.builder() | ||
.put("gcp.client.version", GaxProperties.getLibraryVersion(this.getClass())) | ||
.put("gcp.client.version", storageOptions.getLibraryVersion()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
.put("gcp.client.repo", "googleapis/java-storage") | ||
.put("gcp.client.artifact", "com.google.cloud.google-cloud-storage") | ||
.put("gcp.client.artifact", "com.google.cloud:google-cloud-storage") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the maven package format |
||
.put("rpc.system", transport) | ||
.build()); | ||
return spanBuilder; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Set of internal utilities to make our OTel use a bit more terse. | ||
* | ||
* <p>All classes, interfaces, etc are considered to be for internal library use only and can break | ||
* at any time. | ||
*/ | ||
@InternalApi | ||
package com.google.cloud.storage.otel; | ||
|
||
import com.google.api.core.InternalApi; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed variables to remove warnings from intellij.