Skip to content

User_id column empty in Application Insights logs #4578

@kevveh

Description

@kevveh

Hello,

I inherited a Spring boot application, which uses Application Insights.

Originally, the following maven packages were used:

<dependency>
      <groupId>com.microsoft.azure</groupId>
      <artifactId>applicationinsights-spring-boot-starter</artifactId>
      <version>2.6.4</version>
  </dependency>

  <dependency>
      <groupId>com.microsoft.azure</groupId>
      <artifactId>applicationinsights-logging-logback</artifactId>
      <version>2.6.4</version>
  </dependency>

The user_id was set as follows:

RequestTelemetry requestTelemetry = ThreadContext.getRequestTelemetryContext().getHttpRequestTelemetry();
requestTelemetry.getContext().getUser().setId(email);

Using the setup above, I was able to check traces in the logs, and filter on user (user_id column):

Image

I've since upgraded to the 3.X SDK, using the following:

  • Maven packages:
<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>applicationinsights-web</artifactId>
    <version>3.7.2</version>
</dependency>

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>applicationinsights-runtime-attach</artifactId>
    <version>3.7.2</version>
</dependency>
  • Initialize telemetry:
public static void main(String[] args) {
    ApplicationInsights.attach();
    SpringApplication.run(MsPlanningApplication.class, args);
}
  • Set user id:
RequestTelemetryContext requestTelemetryContext = ThreadContext.getRequestTelemetryContext();
if (requestTelemetryContext != null) {
    RequestTelemetry requestTelemetry = requestTelemetryContext.getHttpRequestTelemetry();
    requestTelemetry.getContext().getUser().setId(email);
}

However, since the upgrade to SDK 3.X, the user_id column is empty (the messages/errors are logged just fine). When I check the end-to-end transaction, I do see my user_id.

So, why am I not seeing the user_id in my traces (when checking the logs)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions