RUMM-409 Unify service
, env
and version
across all SDKs
#102
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What and why?
📦 This PR unifies 3 common attributes across all Datadog SDKs. Similar changes were already applied to Android SDK (#248, #241, #240).
1/ Environment:
This attribute is specified by the user when initializing the SDK and cannot be overwritten any later:
It is sent to Datadog as default tag in log JSON, i.e.:
💡 NOTE: this changes the public API by introducing mandatory
environment:
argument.2/ Service Name:
The default value of this attribute can be optionally specified by the user when initializing the SDK:
If not given, it defaults to the app bundle identifier (i.e.
com.datadoghq.app
).The service name can be overwritten per
Logger
instance usingLogger.Builder
:It is sent do Datadog as
.service
attribute in log JSON, i.e.:💡 NOTE: this changes the
service
default value, which previously was evaluated to"ios"
.3/ Application version:
This attribute is automatically inferred from application
Bundle
. It is sent to Datadog as as.version
attribute in log JSON, i.e.:💡 NOTE: this changes the coding key for application version (before, it was
application.version
).How?
All three attributes are resolved using both arguments from the public
Datadog.initialize()
API:Their resolution can lead to many corner cases, i.e.:
configuration.environment
contains invalid characters (e.x."*(#@"
).configuration.serviceName
is not given, it should be inferred fromappContext.bundleIdentifier
, which can also benil
.appContext.bundleVertsion
can benil
so fallback must be provided.To not leak this corner cases to other SDK components, I created a type-safe representation of valid SDK configuration:
The
ValidConfiguration
is now the only dependency passed down to features, which cuts off many edge cases consideration and centralizes unit testing toValidConfiguration
.Other things done in this PR
It was possible to make
LogBuilder
independent of the publicAppContext
. Now it consumes only plain, non-optional values:This turned out to be highly effective, as the
LoggerBuilderTests
do not require full-feature mocking and assertions can be made onLogOutput
andLogBuilder
.Newly introduced
LoggerBuilderTests
unrevealed one bug that we had:It's also fixed now 👍.
Review checklist
docs/
folder, get it reviewed