Skip to content

[BUG] SDK LOAD Failure reporting not working #2027

Closed
@MichelJansson

Description

@MichelJansson

Description/Screenshot
SDK LOAD Failure is not being sent successfully with instrumentation key errors as response.
This is all due to a mix of issues in the actual snippet code but also the snippet as presented in the README: see additional context below.

Steps to Reproduce

  1. Use latest snippet from README
  2. Configure using connection string as copied from Azure portal:
    connectionString: "InstrumentationKey=[KEY];IngestionEndpoint=[ENDPOINT];LiveEndpoint=[LIVEENDPOINT]"
  3. Enter an invalid URL as script src to simulate loading error
  4. Load page and inspect track request.
    • Notice iKey of payload containing the entire connection string and not just the instrumentation key.
    • Notice the http 400 response with "Invalid instrumentation key" message.

Expected behavior
Connection string to be parsed correctly and exception being tracked successfully.

Additional context

  • Using connection string only has not been working for quite some time due to a mistake in the snippet:

    1. The connection string is being parsed and it's parts is being stored as lower case in the snippet
      var kvPairs = connectionString.split(";");
      for (var lp = 0; lp < kvPairs.length; lp++) {
      var kvParts = kvPairs[lp].split("=");
      if (kvParts.length === 2) { // only save fields with valid formats
      fields[kvParts[0][strToLowerCase]()] = kvParts[1];
      }
      }
    2. But then when the load error code tries to get the instrumentation key from the connection string, it uses a constant that is not lower case which results in no instrumentation key being found.
      var conString = _parseConnectionString();
      var iKey = conString[strInstrumentationKey] || aiConfig[strInstrumentationKey] || strEmpty;
  • The above issue used to possible to be worked around by also providing an instrumenctionKey in the snippet config that then would be used instead, but with the snippet from the current readme this no longer works due:

    1. Someone updated the readme to remove instrumentation key config, and I suppose accidentally also replaced the constant D in the snippet from instrumentationKey to connectionString.
    2. This leads to the entire connection string being passed as iKey as noted of the repro steps.

I am willing to post a PR if you are open for that.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions