-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from breedx-splk/introduce-config
Introduce configuration for instrumentation components (phase 1)
- Loading branch information
Showing
8 changed files
with
327 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
instrumentation/src/main/java/io/opentelemetry/android/OtelRumConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android; | ||
|
||
import io.opentelemetry.android.instrumentation.network.CurrentNetworkProvider; | ||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.common.AttributesBuilder; | ||
|
||
/** | ||
* Configuration object for OpenTelemetry Android. The configuration items in this class will be | ||
* used in the OpenTelemetryRumBuilder to wire up and enable/disable various mobile instrumentation | ||
* components. | ||
*/ | ||
public class OtelRumConfig { | ||
|
||
private AttributesBuilder globalAttributes = Attributes.builder(); | ||
private boolean includeNetworkAttributes = true; | ||
private boolean generateSdkInitializationEvents = true; | ||
private boolean includeScreenAttributes = true; | ||
|
||
/** | ||
* Configures the set of global attributes to emit with every span and event. Any existing | ||
* configured attributes will be dropped. Default = none. | ||
*/ | ||
public OtelRumConfig setGlobalAttributes(Attributes attributes) { | ||
globalAttributes = attributes.toBuilder(); | ||
return this; | ||
} | ||
|
||
boolean hasGlobalAttributes() { | ||
return !globalAttributes.build().isEmpty(); | ||
} | ||
|
||
Attributes getGlobalAttributes() { | ||
return globalAttributes.build(); | ||
} | ||
|
||
/** | ||
* Disables the collection of runtime network attributes. See {@link CurrentNetworkProvider} for | ||
* more information. Default = true. | ||
* | ||
* @return this | ||
*/ | ||
public OtelRumConfig disableNetworkAttributes() { | ||
includeNetworkAttributes = false; | ||
return this; | ||
} | ||
|
||
/** Returns true if runtime network attributes are enabled, false otherwise. */ | ||
public boolean shouldIncludeNetworkAttributes() { | ||
return includeNetworkAttributes; | ||
} | ||
|
||
/** | ||
* Disables the collection of events related to the initialization of the OTel Android SDK | ||
* itself. Default = true. | ||
* | ||
* @return this | ||
*/ | ||
public OtelRumConfig disableSdkInitializationEvents() { | ||
this.generateSdkInitializationEvents = false; | ||
return this; | ||
} | ||
|
||
/** Returns true if the SDK is configured to generate initialization events, false otherwise. */ | ||
public boolean shouldGenerateSdkInitializationEvents() { | ||
return generateSdkInitializationEvents; | ||
} | ||
|
||
/** | ||
* Call this to disable the collection of screen attributes. See {@link | ||
* ScreenAttributesSpanProcessor} for more information. Default = true. | ||
* | ||
* @return this | ||
*/ | ||
public OtelRumConfig disableScreenAttributes() { | ||
this.includeScreenAttributes = false; | ||
return this; | ||
} | ||
|
||
/** Return true if the SDK should be configured to report screen attributes. */ | ||
public boolean shouldIncludeScreenAttributes() { | ||
return includeScreenAttributes; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
instrumentation/src/main/java/io/opentelemetry/android/ScreenAttributesSpanProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android; | ||
|
||
import static io.opentelemetry.android.RumConstants.SCREEN_NAME_KEY; | ||
|
||
import io.opentelemetry.android.instrumentation.activity.VisibleScreenTracker; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.sdk.trace.ReadWriteSpan; | ||
import io.opentelemetry.sdk.trace.ReadableSpan; | ||
import io.opentelemetry.sdk.trace.SpanProcessor; | ||
|
||
class ScreenAttributesSpanProcessor implements SpanProcessor { | ||
|
||
private final VisibleScreenTracker visibleScreenTracker; | ||
|
||
public ScreenAttributesSpanProcessor(VisibleScreenTracker visibleScreenTracker) { | ||
this.visibleScreenTracker = visibleScreenTracker; | ||
} | ||
|
||
@Override | ||
public void onStart(Context parentContext, ReadWriteSpan span) { | ||
String currentScreen = visibleScreenTracker.getCurrentlyVisibleScreen(); | ||
span.setAttribute(SCREEN_NAME_KEY, currentScreen); | ||
} | ||
|
||
@Override | ||
public boolean isStartRequired() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void onEnd(ReadableSpan span) { | ||
// nop | ||
} | ||
|
||
@Override | ||
public boolean isEndRequired() { | ||
return false; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
.../src/main/java/io/opentelemetry/android/instrumentation/startup/InitializationEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.instrumentation.startup; | ||
|
||
import io.opentelemetry.android.OtelRumConfig; | ||
|
||
public interface InitializationEvents { | ||
|
||
void sdkInitializationStarted(); | ||
|
||
void recordConfiguration(OtelRumConfig config); | ||
|
||
void currentNetworkProviderInitialized(); | ||
|
||
InitializationEvents NO_OP = | ||
new InitializationEvents() { | ||
@Override | ||
public void sdkInitializationStarted() {} | ||
|
||
@Override | ||
public void recordConfiguration(OtelRumConfig config) {} | ||
|
||
@Override | ||
public void currentNetworkProviderInitialized() {} | ||
}; | ||
} |
26 changes: 26 additions & 0 deletions
26
...c/main/java/io/opentelemetry/android/instrumentation/startup/SdkInitializationEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.instrumentation.startup; | ||
|
||
import io.opentelemetry.android.OtelRumConfig; | ||
|
||
public class SdkInitializationEvents implements InitializationEvents { | ||
|
||
@Override | ||
public void sdkInitializationStarted() { | ||
// TODO: Build me | ||
} | ||
|
||
@Override | ||
public void recordConfiguration(OtelRumConfig config) { | ||
// TODO: Build me (create event containing the config params for the sdk) | ||
} | ||
|
||
@Override | ||
public void currentNetworkProviderInitialized() { | ||
// TODO: Build me | ||
} | ||
} |
Oops, something went wrong.