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: added support to set version dynamically based on the release #30

Merged
merged 5 commits into from
May 24, 2024
Merged
Changes from 4 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
33 changes: 23 additions & 10 deletions src/DatadogLoggingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,25 @@ class DatadogLoggingService extends NewRelicLoggingService {
}

initialize() {
const requiredDatadogConfig = [
process.env.DATADOG_APPLICATION_ID,
process.env.DATADOG_CLIENT_TOKEN,
];
const hasRequiredDatadogConfig = requiredDatadogConfig.every(value => !!value);

// Do not attempt to initialize Datadog if required config settings are not supplied.
if (!hasRequiredDatadogConfig) {
return;
}

const datadogVersion = process.env.DATADOG_VERSION || process.env.APP_VERSION || '1.0.0';
datadogRum.init({
applicationId: process.env.DATADOG_APPLICATION_ID,
clientToken: process.env.DATADOG_CLIENT_TOKEN,
site: process.env.DATADOG_SITE,
service: process.env.DATADOG_SERVICE,
env: process.env.DATADOG_ENV,
version: process.env.DATADOG_VERSION,
applicationId: process.env.DATADOG_APPLICATION_ID || '',
adamstankiewicz marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: given the required config settings check is implemented above, the applicationId and clientToken properties probably don't need to fallback to an empty string since they should be expected to have a value at this point.

The other fallbacks to empty strings for the other properties still makes sense, though :)

clientToken: process.env.DATADOG_CLIENT_TOKEN || '',
site: process.env.DATADOG_SITE || '',
service: process.env.DATADOG_SERVICE || '',
env: process.env.DATADOG_ENV || '',
version: datadogVersion,
sessionSampleRate: parseInt(process.env.DATADOG_SESSION_SAMPLE_RATE || 0, 10),
sessionReplaySampleRate: parseInt(process.env.DATADOG_SESSION_REPLAY_SAMPLE_RATE || 0, 10),
trackUserInteractions: true,
Expand All @@ -43,12 +55,13 @@ class DatadogLoggingService extends NewRelicLoggingService {
defaultPrivacyLevel: 'mask-user-input',
});
datadogLogs.init({
clientToken: process.env.DATADOG_CLIENT_TOKEN,
site: process.env.DATADOG_SITE,
env: process.env.DATADOG_ENV,
clientToken: process.env.DATADOG_CLIENT_TOKEN || '',
site: process.env.DATADOG_SITE || '',
env: process.env.DATADOG_ENV || '',
forwardErrorsToLogs: true,
sessionSampleRate: parseInt(process.env.DATADOG_LOGS_SESSION_SAMPLE_RATE || 0, 10),
service: process.env.DATADOG_SERVICE,
service: process.env.DATADOG_SERVICE || '',
version: datadogVersion,
});
}

Expand Down
Loading