Skip to content
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

Feat: Allow setting SDK info (name & version) in manifest #2016

Merged
merged 5 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

* Feat: Allow setting SDK info (name & version) in manifest (#2016)

## 6.0.0-beta.3

Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Contributing to sentry-java

We love pull requests from everyone.
We love pull requests from everyone.
We suggest opening an issue to discuss bigger changes before investing on a big PR.

# Requirements

The project currently requires you run JDK version `1.8.x`.
The project currently requires you run JDK 11.

## Android
## Android

This repository is a monorepo which includes Java and Android libraries.
If you'd like to contribute to Java and don't have an Android SDK with NDK installed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.Bundle;
import io.sentry.ILogger;
import io.sentry.SentryLevel;
import io.sentry.protocol.SdkVersion;
import io.sentry.util.Objects;
import java.util.Arrays;
import java.util.List;
Expand All @@ -31,6 +32,8 @@ final class ManifestMetadataReader {
static final String NDK_SCOPE_SYNC_ENABLE = "io.sentry.ndk.scope-sync.enable";
static final String RELEASE = "io.sentry.release";
static final String ENVIRONMENT = "io.sentry.environment";
static final String SDK_NAME = "io.sentry.sdk.name";
static final String SDK_VERSION = "io.sentry.sdk.version";

// TODO: remove on 6.x in favor of SESSION_AUTO_TRACKING_ENABLE
static final String SESSION_TRACKING_ENABLE = "io.sentry.session-tracking.enable";
Expand Down Expand Up @@ -241,6 +244,15 @@ static void applyMetadata(

options.setProguardUuid(
readString(metadata, logger, PROGUARD_UUID, options.getProguardUuid()));

SdkVersion sdkInfo = options.getSdkVersion();
vaind marked this conversation as resolved.
Show resolved Hide resolved
if (sdkInfo == null) {
// Is already set by the Options constructor, let's use an empty default otherwise.
sdkInfo = new SdkVersion("", "");
}
sdkInfo.setName(readStringNotNull(metadata, logger, SDK_NAME, sdkInfo.getName()));
sdkInfo.setVersion(readStringNotNull(metadata, logger, SDK_VERSION, sdkInfo.getVersion()));
options.setSdkVersion(sdkInfo);
}

options
Expand Down Expand Up @@ -274,6 +286,16 @@ private static boolean readBool(
return value;
}

private static @NotNull String readStringNotNull(
final @NotNull Bundle metadata,
final @NotNull ILogger logger,
final @NotNull String key,
final @NotNull String defaultValue) {
final String value = metadata.getString(key, defaultValue);
logger.log(SentryLevel.DEBUG, "%s read: %s", key, value);
return value;
}

private static @Nullable List<String> readList(
final @NotNull Bundle metadata, final @NotNull ILogger logger, final @NotNull String key) {
final String value = metadata.getString(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,36 @@ class ManifestMetadataReaderTest {
assertTrue(fixture.options.isEnableNdk)
}

@Test
fun `applyMetadata reads SDK name from metadata`() {
// Arrange
val expectedValue = "custom.sdk"

val bundle = bundleOf(ManifestMetadataReader.SDK_NAME to expectedValue)
val context = fixture.getContext(metaData = bundle)

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options)

// Assert
assertEquals(expectedValue, fixture.options.sdkVersion?.name)
}

@Test
fun `applyMetadata reads SDK version from metadata`() {
// Arrange
val expectedValue = "1.2.3-alpha.0"

val bundle = bundleOf(ManifestMetadataReader.SDK_VERSION to expectedValue)
val context = fixture.getContext(metaData = bundle)

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options)

// Assert
assertEquals(expectedValue, fixture.options.sdkVersion?.version)
}

@Test
fun `applyMetadata reads enableScopeSync to options`() {
// Arrange
Expand Down