Skip to content

help: Can't migrate code from version 2 to 3 #1414

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

Open
TWpgo opened this issue Feb 4, 2025 · 2 comments
Open

help: Can't migrate code from version 2 to 3 #1414

TWpgo opened this issue Feb 4, 2025 · 2 comments

Comments

@TWpgo
Copy link

TWpgo commented Feb 4, 2025

I have the following code snippet which works great with version 2 but I don't get it working properly with version 3.
Maybe someone could help me:

const appInsights = require("applicationinsights");
const { CorrelationContextManager } = require("applicationinsights/out/AutoCollection/CorrelationContextManager");
const Traceparent = require("applicationinsights/out/Library/Traceparent");
const util = require('applicationinsights/out/Library/Util');

async function main() {
    process.env["TRACEPARENT_HEADER"] = `${Traceparent.DEFAULT_VERSION}-${appInsights.getCorrelationContext().operation.id}-${appInsights.getCorrelationContext().operation.parentId}-${Traceparent.DEFAULT_TRACE_FLAG}`;

    ...
	
    const availabilityTelemetry = {
        id: crypto.randomUUID(),
        ...
        tagOverrides: {
            'ai.cloud.role': 'MyCloudRoleName',
            'ai.cloud.roleInstance': myDynamicCloudRoleInstanceVar,
            'ai.application.ver': versionDerivedDuringMainExecution
        },
        properties: {
            ...
        }
    };
    appInsights.defaultClient.trackAvailability(availabilityTelemetry);

}

appInsights.setup(process.env["CONNECTION_STRING"]).start();
const context = CorrelationContextManager.generateContextObject(
    util.w3cTraceId(),
    util.w3cSpanId(),
    'TestCafe'
);

appInsights.wrapWithCorrelationContext(main, context)().then(failedCount => {
    process.exit(failedCount);
});
@TWpgo
Copy link
Author

TWpgo commented Feb 4, 2025

I struggle especially setting the cloudRoleName or ai.application.ver values in version 3.
Also I don't understand the context handeling in version 3. In version 2 it's pretty simple.
But in version 3 I can't modify it.

@JacksonWeber
Copy link
Contributor

Regarding cloudRoleName, it can be configured using the OTEL_RESOURCE_ATTRIBUTES environment variable in 3.x: #1365.

Regarding support for correlation context, please refer to: Application Insights v3.x Unsupported Properties. If you need thiskind of control over the correlation context we suggest staying on 2.x SDK until it's possible to migrate to the Node.js OpenTelemetry distro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants