Skip to content
Open
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
74 changes: 2 additions & 72 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { NitroAppPlugin } from 'nitropack'
import type { TNitroAppInsightsConfig } from '../types'

Check warning on line 2 in src/runtime/plugin.ts

View workflow job for this annotation

GitHub Actions / ci

'TNitroAppInsightsConfig' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 2 in src/runtime/plugin.ts

View workflow job for this annotation

GitHub Actions / ci

'TNitroAppInsightsConfig' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 2 in src/runtime/plugin.ts

View workflow job for this annotation

GitHub Actions / autofix

'TNitroAppInsightsConfig' is defined but never used. Allowed unused vars must match /^_/u
import { useRuntimeConfig } from '#imports'
import _Applicationinsights from 'applicationinsights'
import { metrics, trace, } from "@opentelemetry/api";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { UndiciInstrumentation } from "@opentelemetry/instrumentation-undici"
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http"
import { SEMATTRS_HTTP_URL, SEMATTRS_HTTP_HOST, SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_ROUTE, SEMATTRS_HTTP_SCHEME, SEMATTRS_HTTP_STATUS_CODE, OTEL_STATUS_CODE_VALUE_OK, OTEL_STATUS_CODE_VALUE_ERROR } from "@opentelemetry/semantic-conventions"

Check warning on line 9 in src/runtime/plugin.ts

View workflow job for this annotation

GitHub Actions / ci

'OTEL_STATUS_CODE_VALUE_ERROR' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 9 in src/runtime/plugin.ts

View workflow job for this annotation

GitHub Actions / ci

'OTEL_STATUS_CODE_VALUE_OK' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 9 in src/runtime/plugin.ts

View workflow job for this annotation

GitHub Actions / ci

'OTEL_STATUS_CODE_VALUE_ERROR' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 9 in src/runtime/plugin.ts

View workflow job for this annotation

GitHub Actions / ci

'OTEL_STATUS_CODE_VALUE_OK' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 9 in src/runtime/plugin.ts

View workflow job for this annotation

GitHub Actions / autofix

'OTEL_STATUS_CODE_VALUE_ERROR' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 9 in src/runtime/plugin.ts

View workflow job for this annotation

GitHub Actions / autofix

'OTEL_STATUS_CODE_VALUE_OK' is defined but never used. Allowed unused vars must match /^_/u
import { getResponseStatus, getRequestURL, getRequestProtocol } from 'h3'
import { defu } from 'defu';

Expand All @@ -29,7 +29,8 @@

await nitro.hooks.callHook('applicationinsights:config', defu(config, {}))

const configuration = setup(config)
const configuration = Applicationinsights.setup(config.connectionString)

await nitro.hooks.callHook('applicationinsights:setup', { client: Applicationinsights.defaultClient, configuration })
configuration.start()
await nitro.hooks.callHook('applicationinsights:ready', { client: Applicationinsights.defaultClient })
Expand Down Expand Up @@ -57,74 +58,3 @@
})
})
})


export function setup(config: TNitroAppInsightsConfig) {
// Setup Application Insights using the instrumentation key from the environment variables
const configuration = Applicationinsights.setup(config.connectionString)

if (config.autoCollectRequests !== undefined) {
configuration.setAutoCollectRequests(config.autoCollectRequests)
}

if (config.autoCollectDependencies !== undefined) {
configuration.setAutoCollectDependencies(config.autoCollectDependencies)
}

if (config.autoCollectExceptions !== undefined) {
configuration.setAutoCollectExceptions(config.autoCollectExceptions)
}

if (config.autoCollectHeartbeat !== undefined) {
configuration.setAutoCollectHeartbeat(config.autoCollectHeartbeat)
}

if (config.autoCollectIncomingRequestAzureFunctions !== undefined) {
configuration.setAutoCollectIncomingRequestAzureFunctions(config.autoCollectIncomingRequestAzureFunctions)
}

if (config.autoCollectPreAggregatedMetrics !== undefined) {
configuration.setAutoCollectPreAggregatedMetrics(config.autoCollectPreAggregatedMetrics)
}

if (config.distributedTracingMode !== undefined) {
configuration.setDistributedTracingMode(config.distributedTracingMode)
}

if (config.sendLiveMetrics !== undefined) {
configuration.setSendLiveMetrics(config.sendLiveMetrics)
}

if (config.useDiskRetryCaching !== undefined) {
configuration.setUseDiskRetryCaching(config.useDiskRetryCaching)
}

if (typeof config.autoCollectPerformance === 'object') {
configuration.setAutoCollectPerformance(config.autoCollectPerformance.value, config.autoCollectPerformance.collectExtendedMetrics)
}
if (typeof config.autoDependencyCorrelation === 'object') {
configuration.setAutoDependencyCorrelation(config.autoDependencyCorrelation.value, config.autoDependencyCorrelation.useAsyncHooks)
} else {
configuration.setAutoDependencyCorrelation(config.autoDependencyCorrelation)
}

if (typeof config.enableWebInstrumentation === 'object') {
configuration.enableWebInstrumentation(config.enableWebInstrumentation.value, config.enableWebInstrumentation.WebSnippetConnectionString)
} else {
configuration.enableWebInstrumentation(config.enableWebInstrumentation)
}

if (typeof config.autoCollectConsole === 'object') {
configuration.setAutoCollectConsole(config.autoCollectConsole.value, config.autoCollectConsole.collectConsoleLogs)
} else {
configuration.setAutoCollectConsole(config.autoCollectConsole)
}

if (typeof config.internalLogging === 'object') {
configuration.setInternalLogging(config.internalLogging.enableDebugLogging, config.internalLogging.enableWarningLogging)
} else {
configuration.setInternalLogging(config.internalLogging)
}

return configuration
}
57 changes: 0 additions & 57 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,6 @@
/// <reference types="nitropack" />
/// <reference types="nitro-opentelemetry" />
import type { DistributedTracingModes } from 'applicationinsights'

export type TNitroAppInsightsConfig = {
connectionString?: string
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
autoCollectRequests: boolean
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
autoCollectConsole: boolean | {value: boolean, collectConsoleLogs: boolean}
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
autoCollectDependencies: boolean
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
autoCollectExceptions: boolean
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
autoCollectPerformance: {value :boolean, collectExtendedMetrics: boolean}
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
autoCollectHeartbeat: boolean
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
autoCollectIncomingRequestAzureFunctions: boolean
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
autoCollectPreAggregatedMetrics: boolean
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
autoDependencyCorrelation: boolean | {value :boolean, useAsyncHooks :boolean}
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
enableWebInstrumentation: boolean | {value: boolean, WebSnippetConnectionString?: string}
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
distributedTracingMode: DistributedTracingModes
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
sendLiveMetrics:boolean
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
internalLogging: {enableDebugLogging?: boolean, enableWarningLogging?: boolean}
/**
* @deprecated since 1.1.0 prefer using applicationinsights:setup hook and modify the configuration object
*/
useDiskRetryCaching: boolean
}
Loading