Skip to content

Instantly share code, notes, and snippets.

@lmolkova
lmolkova / azure-sdk-for-java-config-usage.md
Last active January 26, 2022 01:02
New configuration in Azure SDK for Java
  • SDKs expose IAzureClientBuilder<EventHubProducerClient, EventHubProducerClientOptions> AddEventHubProducerClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration) where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration>

    • Configuration format and binding to options are not defined in Azure SDKs
  • Implementation lives in Microsoft.Extensions.Azure

    • binding to options is done by microsoft.extensions.configuration through IConfiguration.Bind() and relies on *Options following microsoft.extensions.configuration conventions (i.e. properties)
    • options sources are whatever microsoft.extensions.configuration supports:
  • Config

@lmolkova
lmolkova / configuration_azure_sdk.md
Last active January 13, 2022 20:29
Configuration in Azure SDK for Java
@Autowired
ServiceBusSenderClient serviceBusClient;
@PostMapping("/queues")
public String send(@RequestParam("message") String message) {
serviceBusClient.sendMessage(new ServiceBusMessage(message));
return message;
}
@lmolkova
lmolkova / extract_activity_context.cs
Last active December 16, 2021 19:01
Azure SDK ExtractContext exmaples
public static class MessagingExtensions
{
// potential addition to event hubs SDK. service bus is similar
// The only concern is availability of ActivityContext prior to .NET 5
// there is a potential to update DiagnosticSource, but it's problematic because of
// version conflict: binding redirects on .NET Fx and version conflicts with Functions load contexts
public static ActivityContext ExtractTraceContext(this EventData @event)
{
if (@event.Properties.TryGetValue("Diagnostic-Id", out var tp) && tp is string traceparent)
{
package org.example.functions;
import com.azure.core.models.CloudEvent;
import com.azure.core.util.serializer.TypeReference;
import com.azure.messaging.eventgrid.EventGridEvent;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpMethod;
import com.microsoft.azure.functions.HttpRequestMessage;
@lmolkova
lmolkova / context_key_shading.java
Last active November 18, 2021 07:59
Context key shading issues
public static void main(String[] args) {
// first call in not instrumented...
doSomething();
doSomething().transform(t -> {
Span s = GlobalOpenTelemetry.getTracer("test")
.spanBuilder("span")
.startSpan();
return t.doFinally(signal -> s.end())

HTTP

  • P0 - Define span modelling conventions for HTTP client spans #1747
  • Replace http.target with http.path and http.query? #2056
  • Remove http.XX_content_length* semantic attributes #2028
  • P0 - Confirm that HTTP instrumentations can provide sampling-relevant attributes at creation time #2011
  • P? - required/optional #2114

P0 - Retries

private static final Method SET_REACTOR_CONTEXT_METHOD = getStoreContextMethod();
static Method getStoreContextMethod() {
try {
Class<?> contextPropagationOperatorClass = Class.forName("io.opentelemetry.javaagent.shaded.instrumentation.reactor.ContextPropagationOperator");
Class<?> oteContextShaded = Class.forName("io.opentelemetry.javaagent.shaded.io.opentelemetry.context.Context");
if (contextPropagationOperatorClass != null && oteContextShaded != null) {
Method storeMethod = contextPropagationOperatorClass.getDeclaredMethod("storeOpenTelemetryContext", reactor.util.context.Context.class, oteContextShaded);
if (storeMethod.getReturnType() == reactor.util.context.Context.class) {
return storeMethod;
}