Skip to content

Commit eb27a05

Browse files
authored
Merge pull request #1432 from clearlydefined/fix/appinsights-connection-string
Fix App Insights 3.x connection string configuration
2 parents 5578aa9 + dacbd2f commit eb27a05

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

lib/mockInsights.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ declare class MockInsights {
2525
/**
2626
* Sets up the Application Insights abstraction layer
2727
*
28-
* @param key - Application Insights instrumentation key. If null, undefined, or 'mock', uses console-based logging
28+
* @param connectionString - Application Insights connection string. If null, undefined, or 'mock', uses console-based logging
2929
* @param echo - Whether to echo telemetry to both console and Application Insights client when both are available
3030
*/
31-
static setup(key?: string | null, echo?: boolean): void
31+
static setup(connectionString?: string | null, echo?: boolean): void
3232

3333
/**
3434
* Tracks an exception

lib/mockInsights.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@ class MockInsights {
6464

6565
/**
6666
* Sets up the Application Insights abstraction layer. This method configures the telemetry client
67-
* based on the provided key, creating either a full Application Insights client or a console-based fallback wrapper.
67+
* based on the provided connection string, creating either a full Application Insights client or a console-based fallback wrapper.
6868
*
69-
* @param {string | null} [key=null] - Application Insights instrumentation key. If null, undefined, or 'mock', uses
70-
* console-based logging. Default is `null`
69+
* @param {string | null} [connectionString=null] - Application Insights connection string. If null, undefined, or
70+
* 'mock', uses console-based logging. Default is `null`
7171
* @param {boolean} [echo=false] - Whether to echo telemetry to both console and Application Insights client when both
7272
* are available. Default is `false`
7373
* @returns {void}
7474
*/
75-
static setup(key = null, echo = false) {
75+
static setup(connectionString = null, echo = false) {
7676
// exit if we are already setup
7777
if (_client instanceof MockInsights) return
78-
if (!key || key === 'mock') {
78+
if (!connectionString || connectionString === 'mock') {
7979
_client = new MockInsights()
8080
} else {
81-
appInsights.setup(key).setAutoCollectPerformance(false).setAutoCollectDependencies(true).start()
81+
appInsights.setup(connectionString).setAutoCollectPerformance(false).setAutoCollectDependencies(true).start()
8282
if (echo) {
8383
_client = new MockInsights(appInsights.defaultClient)
8484
} else {

providers/logging/winstonConfig.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import * as winston from 'winston'
66
/** Configuration options for creating a Winston logger instance. */
77
export interface WinstonLoggerOptions {
88
/**
9-
* Application Insights instrumentation key for logging. If not provided, uses APPINSIGHTS_INSTRUMENTATIONKEY from
10-
* config.
9+
* Application Insights connection string for logging. If not provided, uses APPLICATIONINSIGHTS_CONNECTION_STRING
10+
* from config.
1111
*/
12-
key?: string
12+
connectionString?: string
1313

1414
/**
1515
* Whether to echo log messages to the console.

providers/logging/winstonConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ const mockInsights = require('../../lib/mockInsights')
1616

1717
function factory(options) {
1818
const realOptions = {
19-
key: config.get('APPINSIGHTS_INSTRUMENTATIONKEY'),
19+
connectionString: config.get('APPLICATIONINSIGHTS_CONNECTION_STRING'),
2020
echo: config.get('LOGGER_LOG_TO_CONSOLE') === 'true',
2121
level: config.get('APPINSIGHTS_EXPORT_LOG_LEVEL') || 'info',
2222
...options
2323
}
2424

25-
mockInsights.setup(realOptions.key || 'mock', realOptions.echo)
25+
mockInsights.setup(realOptions.connectionString || 'mock', realOptions.echo)
2626

2727
const logFormat = winston.format.combine(
2828
winston.format.timestamp(),

0 commit comments

Comments
 (0)