Skip to content

Console.time() generates two telemetry traces #758

Description

@nulltoken

Lib version:

  • applicationinsights: 2.0.0

Given the following code

import { setup, defaultClient } from 'applicationinsights';
import { Contracts } from "applicationinsights";
import {
  Data,
  MessageData,
} from "applicationinsights/out/Declarations/Contracts";

const telemetryConsoleLogger = (envelope: Contracts.Envelope, _contextObjects?: {
  [name: string]: unknown;
}): boolean => {
  if (envelope.data.baseType !== "MessageData") {
    return true;
  }

  const data = envelope.data as Data<MessageData>;
  console.log("Logged: " + data.baseData.message);
  return true;
};

const sleep = (ms: number): Promise<void> => {
  return new Promise(resolve => setTimeout(resolve, ms));
}

void (async function () {
  setup("_your_ikey_")
    .setAutoCollectConsole(true, true)
    .start();

  defaultClient.addTelemetryProcessor(telemetryConsoleLogger);

  console.log("Hello")
  console.time("Test")
  await sleep(150)
  console.timeEnd("Test")
  console.log("Goodbye")
})();

The following is dumped in the console.

ApplicationInsights:An invalid instrumentation key was provided. There may be resulting telemetry loss [ '_your_ikey_' ]
Logged: Hello
Hello
Logged: Test: 153.578ms   # <-- Here.
Logged: Test: 155.478ms
Test: 155.478ms
Logged: Goodbye
Goodbye

I'm not sure why Logged: Test: 153.578ms goes through the telemetry processor, but that looks like an unexpected behavior.

This has been discovered while going through Azure ApplicationInsights logs and generates quite a bit of pollution...

Activity

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions