Remove Obfuscated marker interface. (#2221)

* Remove Obfuscated marker interface.

* Drift

* Update OpenTelemetrySdk.java
This commit is contained in:
Anuraag Agrawal 2020-12-09 13:59:04 +09:00 committed by GitHub
parent a439ca6da1
commit 9d9c88a78b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 35 deletions

View File

@ -1,30 +0,0 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.sdk;
import javax.annotation.concurrent.ThreadSafe;
/**
* This interface allows the SDK to unobfuscate an obfuscated static global provider.
*
* <p>Static global providers are obfuscated when they are returned from the API to prevent users
* from casting them to their SDK specific implementation.
*
* <p>This is important for auto-instrumentation, because if users take the static global providers
* that are returned from the API, and cast them to their SDK specific implementations, then those
* casts will fail under auto-instrumentation, because auto-instrumentation takes over the static
* global providers returned by the API and points them to it's embedded SDK.
*/
@ThreadSafe
interface Obfuscated<T> {
/**
* Returns the unobfuscated provider.
*
* @return the unobfuscated provider.
*/
T unobfuscate();
}

View File

@ -271,14 +271,15 @@ public final class OpenTelemetrySdk extends DefaultOpenTelemetry {
}
/**
* A {@link TracerProvider} wrapper that forces users to access the SDK specific implementation
* via the SDK, instead of via the API and casting it to the SDK specific implementation.
* This class allows the SDK to unobfuscate an obfuscated static global provider.
*
* @see Obfuscated
* <p>Static global providers are obfuscated when they are returned from the API to prevent users
* from casting them to their SDK specific implementation. For example, we do not want users to
* use patterns like {@code (TracerSdkProvider) OpenTelemetry.getGlobalTracerProvider()}.
*/
@ThreadSafe
// Visible for testing
static class ObfuscatedTracerProvider implements TracerProvider, Obfuscated<TracerProvider> {
static class ObfuscatedTracerProvider implements TracerProvider {
private final TracerProvider delegate;
@ -296,7 +297,6 @@ public final class OpenTelemetrySdk extends DefaultOpenTelemetry {
return delegate.get(instrumentationName, instrumentationVersion);
}
@Override
public TracerProvider unobfuscate() {
return delegate;
}