I've recently been implementing correlation between a queue producer and queue consumer, as per the documentation, and hit a snag in the form of insufficient info from the SDK.
TL;DR: There is no stable/documented/extant way to get a RemoteDependencyTelemetry's operation ID or actual ID, because they aren't generated until after being tracked.
As I understand the process, the producer side needs to include both its ID and its operation ID. The problem seems to be that the operation ID is not populated until after the call to TelemetryClient.trackDependency(RemoteDependencyTelemetry). Indeed, in the documentation the sample code uses an extension method StartOperation<T>, which sets up an operation ID on its own that is then used to establish correlation.
In Java, there doesn't appear to be any equivalent.
As far as the ID of the RemoteDependencyTelemetry itself, I'm not 100% because I don't know this codebase all that well, but I can't find where or how it is ever set at all. The .NET code appears to just generate a random int and base64-encode the binary representation of said int; I don't know whether/how that will work with the Java SDK.
Describe the solution you would like
I'd like support in the stable API for initializing operation IDs prior to tracking events, so that we can correlate producer/consumer workflows without relying on internal APIs.
Describe alternatives you have considered
I'm currently duplicating logic found in the internal WebOperationIdTelemetryInitializer class in my own code, which is obviously going to be fragile:
RemoteDependencyTelemetry rdp = ...
String rootId = generateRandomBase64Id():
String parentId = return ThreadContext.getRequestTelemetryContext()
.getHttpRequestTelemetry()
.getContext()
.getOperation()
.getId();
dep.setId(rootId);
try {
enqueueWork(rootId, parentId, theWork);
rdp.success = true
} catch (e: Exception) {
rdp.success = false
}
telemetryClient.trackDependency(rdp)
I've recently been implementing correlation between a queue producer and queue consumer, as per the documentation, and hit a snag in the form of insufficient info from the SDK.
TL;DR: There is no stable/documented/extant way to get a RemoteDependencyTelemetry's operation ID or actual ID, because they aren't generated until after being tracked.
As I understand the process, the producer side needs to include both its ID and its operation ID. The problem seems to be that the operation ID is not populated until after the call to
TelemetryClient.trackDependency(RemoteDependencyTelemetry). Indeed, in the documentation the sample code uses an extension methodStartOperation<T>, which sets up an operation ID on its own that is then used to establish correlation.In Java, there doesn't appear to be any equivalent.
As far as the ID of the
RemoteDependencyTelemetryitself, I'm not 100% because I don't know this codebase all that well, but I can't find where or how it is ever set at all. The .NET code appears to just generate a random int and base64-encode the binary representation of said int; I don't know whether/how that will work with the Java SDK.Describe the solution you would like
I'd like support in the stable API for initializing operation IDs prior to tracking events, so that we can correlate producer/consumer workflows without relying on internal APIs.
Describe alternatives you have considered
I'm currently duplicating logic found in the internal
WebOperationIdTelemetryInitializerclass in my own code, which is obviously going to be fragile: