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

Add possibility to use multiple custom destinations(instrumentation keys) #1674

Closed
born-to-be-mad opened this issue May 5, 2021 · 7 comments · Fixed by #1809
Closed

Add possibility to use multiple custom destinations(instrumentation keys) #1674

born-to-be-mad opened this issue May 5, 2021 · 7 comments · Fixed by #1809

Comments

@born-to-be-mad
Copy link

born-to-be-mad commented May 5, 2021

When custom client is configured with own instrumentation key it is ignored and handled by Agent client:

    @Value("${appinsights.analytics.instrumentationkey}")
    private String instrumentationKey;

    @PostConstruct
    public void init() {
        TelemetryConfiguration telemetryConfiguration = TelemetryConfiguration.createDefault();
        telemetryConfiguration.setInstrumentationKey(instrumentationKey);

        client = new TelemetryClient(telemetryConfiguration);
    }

Agent configuration:

{
  "connectionString": "InstrumentationKey=another-instrumentation-key;IngestionEndpoint=https://eastus2-0.in.applicationinsights.azure.com/",
  "role": {
    "name": "test-service"
  },
  "selfDiagnostics": {
    "destination": "console"
  }
}

The destination(instrumentation key) from custom client should be used, not configured globally in the agent.

Alternatives
We were trying to tune the client, but then we have realized that BytecodeUtilImpl.java#L220 configures agent client in the global scope.

Additional context
The client is set globally in the source code below https://github.com/microsoft/ApplicationInsights-Java/blob/3.0.2/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/instrumentation/sdk/BytecodeUtilImpl.java#L220

@trask
Copy link
Member

trask commented Jun 17, 2021

hey @dma1979! this should work in recent versions if you set the instrumentation key on the telemetry record itself, e.g.

EventTelemetry event = new EventTelemetry("my event");
event.getContext().setInstrumentationKey("...");
client.track(event);

@born-to-be-mad
Copy link
Author

hi @trask , thank you for your piece of advice.

But it still doesn't work by setting intrumentation key on the record itslef:

    private EventTelemetry createEventTelemetry(String name) {
        final var event = new EventTelemetry(name);
        Optional.ofNullable(instrumentationKey)
                .ifPresent(key -> event.getContext().setInstrumentationKey(key));
        return event;
    }

Regarding versions:
"applicationinsights-agent: 3.0.2"
"applicationinsights-web:2.6.3"

@trask
Copy link
Member

trask commented Jun 23, 2021

oh, sorry, you will need 3.0.4 or later for that to work

@born-to-be-mad
Copy link
Author

Thank you @trask for your quick response.
Here the results:

  1. (+) OK, when AppInsightAgent's instrumentation-key and custom event instrumentation-key are different but both belong to the same IngestionEndpoint, f.e. eastus2-0
  2. (+) OK, when custom event instrumentation-key is not set, then just single one from AppInsightAgent's is used.
  3. (-) NOT_OK, when AppInsightAgent's instrumentation-key belongs to one IngestionEndpoint(eastus2-0), but custom event instrumentation-key belongs to another IngestionEndpoint(eastus2-3). No erros, custom events are not tracked. I couldn't find them in bith appinsights.

@kryalama
Copy link
Contributor

kryalama commented Jul 9, 2021

@dma1979 I am guessing the application insights endpoint is redirecting with 308 response when telemetry is sent to eastus2-3. And as of today the agent donot support redirects. Could you please confirm if you see any redirects through debugger tool like Fiddler.

@kryalama
Copy link
Contributor

@dma1979 we are adding support to redirects in the following PR #1809

@trask
Copy link
Member

trask commented Aug 4, 2021

this should work now in 3.2.0-BETA.2

@ghost ghost locked as resolved and limited conversation to collaborators Sep 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants