Skip to content

Commit d0d4729

Browse files
authored
fix: use new config keys (#203)
1 parent ac09edc commit d0d4729

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This package serves an interface for [Microsoft's Application Insights npm modul
88

99
## Usage
1010

11-
### For long running process:
11+
### For long running process
1212

1313
```javascript
1414
import TelemetryReporter from '@salesforce/telemetry';
@@ -26,11 +26,11 @@ By default, some common properties are hidden for GDPR. This is to protect clien
2626
const reporter = await TelemetryReporter.create({
2727
project: 'my-project-name',
2828
key: 'my-instrumentation-key',
29-
gdprSensitiveKeys: []
29+
gdprSensitiveKeys: [],
3030
});
3131
```
3232

33-
### For short lived processes:
33+
### For short lived processes
3434

3535
```javascript
3636
import TelemetryReporter from '@salesforce/telemetry';
@@ -48,4 +48,4 @@ reporter.stop();
4848

4949
## Env Variables
5050

51-
`SFDX_DISABLE_INSIGHTS`: Set to `true` if you want to disable telemetry.
51+
`SF_DISABLE_TELEMETRY`: Set to `true` if you want to disable telemetry.

src/telemetryReporter.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77
import * as os from 'os';
8-
import { Logger, SfdxConfigAggregator } from '@salesforce/core';
8+
import { Logger, SfdxConfigAggregator, SfConfigProperties } from '@salesforce/core';
99
import { AsyncCreatable, env } from '@salesforce/kit';
1010

1111
import axios from 'axios';
1212
import { AppInsights, Attributes, Properties, TelemetryOptions } from './appInsights';
1313
import { TelemetryClient } from './exported';
1414

15-
const DISABLE_TELEMETRY = 'disableTelemetry';
16-
1715
export { TelemetryOptions, Attributes, Properties, TelemetryClient } from './appInsights';
1816

1917
/**
@@ -41,7 +39,8 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
4139
if (!TelemetryReporter.config) {
4240
TelemetryReporter.config = await SfdxConfigAggregator.create({});
4341
}
44-
const configValue = TelemetryReporter.config.getPropertyValue(DISABLE_TELEMETRY);
42+
const configValue = TelemetryReporter.config.getPropertyValue(SfConfigProperties.DISABLE_TELEMETRY);
43+
// SF_DISABLE_TELEMETRY is the proper name for this env that will be cheked by config.getPropertyValue. SFDX_DISABLE_INSIGHTS is present for backwards compatibility
4544
const sfdxDisableInsights = configValue === 'true' || env.getBoolean('SFDX_DISABLE_INSIGHTS');
4645
return !sfdxDisableInsights;
4746
}
@@ -167,7 +166,7 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
167166
* Setting the disableTelemetry config var to true will disable insights for errors and diagnostics.
168167
*/
169168
public isSfdxTelemetryEnabled(): boolean {
170-
const configValue = this.config.getPropertyValue(DISABLE_TELEMETRY);
169+
const configValue = this.config.getPropertyValue(SfConfigProperties.DISABLE_TELEMETRY);
171170
const sfdxDisableInsights = configValue === 'true' || env.getBoolean('SFDX_DISABLE_INSIGHTS');
172171
// isEnabled = !sfdxDisableInsights
173172
return !sfdxDisableInsights;
@@ -177,11 +176,11 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
177176
const isEnabled = this.isSfdxTelemetryEnabled();
178177
if (isEnabled) {
179178
this.logger.warn(
180-
`Telemetry is enabled. This can be disabled by running sfdx force:config:set ${DISABLE_TELEMETRY}=true`
179+
`Telemetry is enabled. This can be disabled by running sfdx force:config:set ${SfConfigProperties.DISABLE_TELEMETRY}=true`
181180
);
182181
} else {
183182
this.logger.warn(
184-
`Telemetry is disabled. This can be enabled by running sfdx force:config:set ${DISABLE_TELEMETRY}=false`
183+
`Telemetry is disabled. This can be enabled by running sfdx force:config:set ${SfConfigProperties.DISABLE_TELEMETRY}=false`
185184
);
186185
}
187186
}

0 commit comments

Comments
 (0)