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

3.0.0-beta.11 - has no exported member 'Context' #1299

Open
jerryjren opened this issue Mar 17, 2024 · 14 comments
Open

3.0.0-beta.11 - has no exported member 'Context' #1299

jerryjren opened this issue Mar 17, 2024 · 14 comments
Assignees

Comments

@jerryjren
Copy link

Hi there,

I have added application insights library to my Azure function app in order to send custom events.
https://learn.microsoft.com/en-us/azure/azure-monitor/app/opentelemetry-add-modify?tabs=nodejs#send-custom-telemetry-using-the-application-insights-classic-api

After npm start, I'm getting the below error. Any suggestion?
image

Another question, my function has associated application insights. Do I still need to use this library? The reason to use this library was I want my logs to be in OpenTelemetry format, hence followed the tutorial below.
https://learn.microsoft.com/en-us/azure/azure-monitor/app/opentelemetry-enable?tabs=nodejs

Func version: 4.0.5455

@JacksonWeber
Copy link
Contributor

Hi @jerryjren, if you've already auto-instrumented your application when you created the Azure Function, you shouldn't need to do any manual instrumentation with this SDK.

If your main goal is to be using OpenTelemetry concepts and instrumentations, I'd suggest using the Azure Monitor OpenTelemetry Distro for Node.js https://www.npmjs.com/package/@azure/monitor-opentelemetry. The intention of the shim is primarily to provide customers already heavily manually instrumented with ApplicationInsights SDK 2.x a simple path forward.

@jerryjren
Copy link
Author

Hi @jerryjren, if you've already auto-instrumented your application when you created the Azure Function, you shouldn't need to do any manual instrumentation with this SDK.

If your main goal is to be using OpenTelemetry concepts and instrumentations, I'd suggest using the Azure Monitor OpenTelemetry Distro for Node.js https://www.npmjs.com/package/@azure/monitor-opentelemetry. The intention of the shim is primarily to provide customers already heavily manually instrumented with ApplicationInsights SDK 2.x a simple path forward.

Hi,

According to this tutorial that opentelemetry nodejs api currently does not support custom events.

It suggested to use application insights class api instead. See below.
https://learn.microsoft.com/en-us/azure/azure-monitor/app/opentelemetry-add-modify?tabs=nodejs#send-custom-telemetry-using-the-application-insights-classic-api

I might be reading it wrong, any suggestions are welcome.

thank you

@JacksonWeber
Copy link
Contributor

@jerryjren Ah, I see. Yes, if you're looking for custom events, you're on the right track.

Based on the error it looks like there's just a type Context that's expected out of your @azure/functions package. Could you let me know what version of @azure/functions you have?

@jerryjren
Copy link
Author

jerryjren commented Mar 25, 2024

@jerryjren Ah, I see. Yes, if you're looking for custom events, you're on the right track.

Based on the error it looks like there's just a type Context that's expected out of your @azure/functions package. Could you let me know what version of @azure/functions you have?

    "@azure/functions": "^4.3.0",
    "@azure/monitor-opentelemetry": "^1.2.0",
    "@opentelemetry/api-logs": "^0.49.1",
    "@opentelemetry/resources": "^1.20.0",
    "@opentelemetry/sdk-logs": "^0.49.1",
    "@opentelemetry/semantic-conventions": "^1.22.0",
    "applicationinsights": "^3.0.0-beta.11",

@JacksonWeber
Copy link
Contributor

@jerryjren It looks like the SDK is not compatible with @azure/functions 4.3.0's types. Could you try setting your @azure/functions package version to 3.2.0?

@JacksonWeber JacksonWeber self-assigned this Apr 12, 2024
@jerryjren
Copy link
Author

@jerryjren It looks like the SDK is not compatible with @azure/functions 4.3.0's types. Could you try setting your @azure/functions package version to 3.2.0?

hey, sorry about late reply.

I tried with @azure/functions package version to 3.2.0, and it works. Thanks for that.

Although I'm encounter another issue saying invalid metric name, even though I'm trying to track event.

Here is the statcktrace


[2024-04-18T06:42:47.497Z] Executing 'Functions.HttpExample' (Reason='This function was programmatically called via the host APIs.', Id=cf6da69c-fbf9-436a-89a6-94030011cf6f)
[2024-04-18T06:42:47.577Z] @azure/opentelemetry-instrumentation-azure-sdk [
[2024-04-18T06:42:47.577Z]   'Module @azure/core-tracing has been loaded before @azure/opentelemetry-instrumentation-azure-sdk so it might not work, please initialize it before requiring @azure/core-tracing'
[2024-04-18T06:42:47.577Z] ]
[2024-04-18T06:42:47.593Z] Invalid metric name: "\ASP.NET Applications(??APP_W3SVC_PROC??)\Request Execution Time". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2024-04-18T06:42:47.593Z] Invalid metric name: "\ASP.NET Applications(??APP_W3SVC_PROC??)\Requests/Sec". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2024-04-18T06:42:47.593Z] Invalid metric name: "\Process(??APP_WIN32_PROC??)\Private Bytes". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2024-04-18T06:42:47.593Z] Invalid metric name: "\Memory\Available Bytes". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2024-04-18T06:42:47.594Z] Invalid metric name: "\Processor(_Total)\% Processor Time". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2024-04-18T06:42:47.594Z] Invalid metric name: "\Process(??APP_WIN32_PROC??)\% Processor Time". The metric name should be a ASCII string with a length no greater than 255 characters. []
[2024-04-18T06:42:47.605Z] Accessing resource attributes before async attributes settled []
[2024-04-18T06:42:47.606Z] Accessing resource attributes before async attributes settled []
[2024-04-18T06:42:47.608Z] Accessing resource attributes before async attributes settled []
[2024-04-18T06:42:47.608Z] Accessing resource attributes before async attributes settled []
[2024-04-18T06:42:47.655Z] HTTP trigger function processed a request.
[2024-04-18T06:42:47.732Z] Executed 'Functions.HttpExample' (Succeeded, Id=cf6da69c-fbf9-436a-89a6-94030011cf6f, Duration=259ms)
[2024-04-18T06:42:52.609Z] Envelopes could not be exported and are not retriable. Error message: [
[2024-04-18T06:42:52.609Z]   'Error "body.data.baseData.ver cannot be null or undefined." occurred in serializing the payload - "body".'
[2024-04-18T06:42:52.610Z] ]
[2024-04-18T06:42:52.610Z] {"stack":"Error: Error \"body.data.baseData.ver cannot be null or undefined.\" occurred in serializing the payload - \"body\".\n    at serializeRequestBody (/Users/jren/src/function-v3/node_modules/@azure/core-client/dist/commonjs/serializationPolicy.js:119:19)\n    at Object.sendRequest (/Users/jren/src/function-v3/node_modules/@azure/core-client/dist/commonjs/serializationPolicy.js:28:17)\n    at /Users/jren/src/function-v3/node_modules/@azure/core-rest-pipeline/dist/commonjs/pipeline.js:54:31\n    at HttpPipeline.sendRequest (/Users/jren/src/function-v3/node_modules/@azure/core-rest-pipeline/dist/commonjs/pipeline.js:57:16)\n    at ApplicationInsightsClient.sendRequest (/Users/jren/src/function-v3/node_modules/@azure/core-client/dist/commonjs/serviceClient.js:48:30)\n    at ApplicationInsightsClient.sendOperationRequest (/Users/jren/src/function-v3/node_modules/@azure/core-client/dist/commonjs/serviceClient.js:110:44)\n    at ApplicationInsightsClient.track (/Users/jren/src/function-v3/node_modules/@azure/monitor-opentelemetry-exporter/dist/index.js:1834:21)\n    at HttpSender.send (/Users/jren/src/function-v3/node_modules/@azure/monitor-opentelemetry-exporter/dist/index.js:2800:38)\n    at HttpSender.exportEnvelopes (/Users/jren/src/function-v3/node_modules/@azure/monitor-opentelemetry-exporter/dist/index.js:2589:55)\n    at /Users/jren/src/function-v3/node_modules/@azure/monitor-opentelemetry-exporter/dist/index.js:3864:47","message":"Error \"body.data.baseData.ver cannot be null or undefined.\" occurred in serializing the payload - \"body\".","name":"Error"} []

Here is my function app

import { AzureFunction, Context, HttpRequest } from "@azure/functions"
import { TelemetryClient } from "applicationinsights";

const telemetryClient = new TelemetryClient();


const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
    context.log('HTTP trigger function processed a request.');
    const name = (req.query.name || (req.body && req.body.name));
    const responseMessage = name
        ? "Hello, " + name + ". This HTTP triggered function executed successfully."
        : "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";

    // Create an event telemetry object.
    let eventTelemetry = {
        name: "testEvent"
      };
  
    // Send the event telemetry object to Azure Monitor Application Insights.
    telemetryClient.trackEvent(eventTelemetry);

    context.res = {
        // status: 200, /* Defaults to 200 */
        body: responseMessage
    };

};

export default httpTrigger;

@JacksonWeber
Copy link
Contributor

@jerryjren That's normal for the OpenTelemetry based SDK. OpenTelemetry complains about the existence of spaces in the metric names for performance counters, but functionality shouldn't be impacted.

@jerryjren
Copy link
Author

jerryjren commented Apr 18, 2024

@jerryjren That's normal for the OpenTelemetry based SDK. OpenTelemetry complains about the existence of spaces in the metric names for performance counters, but functionality shouldn't be impacted.

Cool, just a warning then. Thanks

Last question, do you know which table in App insights will contain the above events? I cannot see anything in customEvents.

I do see logs in requests table, so that can confirm the connection string is correct.

Thanks again

@JacksonWeber
Copy link
Contributor

@jerryjren In OpenTelemetry context (which the beta and now application insights 3.X SDK is built on) customEvents are a form of log. They should appear in the "Transaction Search" blade in the Azure portal. Please let me know if you're not seeing them there. Thanks!

@jerryjren
Copy link
Author

jerryjren commented Apr 19, 2024

@jerryjren In OpenTelemetry context (which the beta and now application insights 3.X SDK is built on) customEvents are a form of log. They should appear in the "Transaction Search" blade in the Azure portal. Please let me know if you're not seeing them there. Thanks!

unfortunately, I'm not seeing anything :(

image

Below is from requests table of same Application insights, just to confirm the application is able to connect to Application insights
image

Update, I'm seeing this error in my function output. Could this be why?

[2024-04-19T05:11:03.217Z] {"stack":"Error: Error \"body.data.baseData.ver cannot be null or undefined.\" occurred in serializing the payload - \"body\".\n at serializeRequestBody (/Users/jren/src/function-v3/node_modules/@azure/core-client/dist/commonjs/serializationPolicy.js:119:19)\n at Object.sendRequest (/Users/jren/src/function-v3/node_modules/@azure/core-client/dist/commonjs/serializationPolicy.js:28:17)\n at /Users/jren/src/function-v3/node_modules/@azure/core-rest-pipeline/dist/commonjs/pipeline.js:54:31\n at HttpPipeline.sendRequest (/Users/jren/src/function-v3/node_modules/@azure/core-rest-pipeline/dist/commonjs/pipeline.js:57:16)\n at ApplicationInsightsClient.sendRequest (/Users/jren/src/function-v3/node_modules/@azure/core-client/dist/commonjs/serviceClient.js:48:30)\n at ApplicationInsightsClient.sendOperationRequest (/Users/jren/src/function-v3/node_modules/@azure/core-client/dist/commonjs/serviceClient.js:110:44)\n at ApplicationInsightsClient.track (/Users/jren/src/function-v3/node_modules/@azure/monitor-opentelemetry-exporter/dist/index.js:1834:21)\n at HttpSender.send (/Users/jren/src/function-v3/node_modules/@azure/monitor-opentelemetry-exporter/dist/index.js:2800:38)\n at HttpSender.exportEnvelopes (/Users/jren/src/function-v3/node_modules/@azure/monitor-opentelemetry-exporter/dist/index.js:2589:55)\n at /Users/jren/src/function-v3/node_modules/@azure/monitor-opentelemetry-exporter/dist/index.js:3864:47","message":"Error \"body.data.baseData.ver cannot be null or undefined.\" occurred in serializing the payload - \"body\".","name":"Error"} []

@JacksonWeber
Copy link
Contributor

@jerryjren Yeah, that looks to be the reason you're not receiving telemetry. Are you still on 3.0.0-beta.11? Or did you upgrade to version 3.0.0 of Application Insights? If you did upgrade, are you using the client.track() method in your code?

@jerryjren
Copy link
Author

@jerryjren Yeah, that looks to be the reason you're not receiving telemetry. Are you still on 3.0.0-beta.11? Or did you upgrade to version 3.0.0 of Application Insights? If you did upgrade, are you using the client.track() method in your code?

I'm using 3.0.0-beta.12 now, and I'm using telemetryClient.trackEvent(eventTelemetry); in my code.

Just tried using 3.0.0, saw same errors in the output.

@JacksonWeber
Copy link
Contributor

@jerryjren Thank you for raising this issue. After investigation, I've resolved the issue with this PR: #1312 and the fix will be available in the next release.

@jerryjren
Copy link
Author

@jerryjren Thank you for raising this issue. After investigation, I've resolved the issue with this PR: #1312 and the fix will be available in the next release.

Thanks for addressing this issue promptly.

One last question, assuming this is working and we are able to see logs in Application Insights, how could we export the logs in Open Telemetry format and forward them to 3rd party i.e.cloudwatch ?

I know this may not be the right place to ask this question. All good if you don't know.

Thanks again

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

No branches or pull requests

2 participants