Skip to content

Conversation

@ahmedmuhsin
Copy link
Contributor

@ahmedmuhsin ahmedmuhsin commented Sep 4, 2025

This pull request introduces several improvements and refactorings to the OpenTelemetry integration for Azure Functions in Java. The main focus is on making the SDK initialization more robust and agent-agnostic, improving resource detection documentation and logic, and updating test dependencies and build plugins for better compatibility and reliability.

SDK Initialization and Robustness

  • Refactored FunctionsOpenTelemetry to support agent-agnostic initialization, caching the global OpenTelemetry instance, and ensuring thread-safe, idempotent setup. Initialization now works seamlessly with or without an OpenTelemetry agent, and avoids unnecessary global registration. [1] [2]
  • Improved error handling and shutdown logic during SDK setup, and switched to using buildAndRegisterGlobal for fallback scenarios.

Resource Detection Documentation and Logic

  • Expanded and clarified Javadoc comments in FunctionsResourceDetector to document the resource detection process, its modes (local vs. Azure-hosted), and the mapping to OpenTelemetry semantic conventions. Attribute and environment variable documentation was made more explicit.
  • Improved code comments and variable naming in resource detection logic for clarity, including construction of ARM resource IDs and deployment environment attributes. [1] [2] [3] [4]

API Usability and Convenience

  • Added new convenience methods and validation helpers for span creation in FunctionsOpenTelemetry, including a default tracer name and overloads for trace context usage.

Build and Test Dependency Updates

  • Updated the project version to 1.1.0 and downgraded junit.jupiter.version to 5.9.3 for compatibility. [1] [2]
  • Added junit-jupiter-engine and junit-platform-launcher test dependencies, and introduced the maven-surefire-plugin for improved test execution. [1] [2]

@ahmedmuhsin ahmedmuhsin marked this pull request as ready for review September 9, 2025 19:06
@ahmedmuhsin ahmedmuhsin requested a review from a team as a code owner September 9, 2025 19:06
if (sdk == null) {
synchronized (FunctionsOpenTelemetry.class) {
if (initialized) {
return; // Fast path - no synchronization needed after initialization

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, why we need initialized parameter fir thread safety, why can't globelOtel can be used.

Concern I have is there are two volatile variables to support same functionality.

`public static void initialize() {
if (globelOtel!= null) {
return; // Fast path
}

    synchronized (FunctionsOpenTelemetry.class) {
        if (globelOtel!= null) {
            return; // Double-check after acquiring lock
        }

        io.opentelemetry.api.OpenTelemetry global = GlobalOpenTelemetry.get();

        if (isNoOp(global)) {
            LOGGER.info("No global OpenTelemetry found; initializing SDK.");
            globelOtel= buildSdk(); 
        } else {
            LOGGER.info("GlobalOpenTelemetry already set; using existing instance.");
            globelOtel= global;
        }
    }
}

`

* Ensures initialization has occurred.
*/
private static void ensureInitialized() {
if (!initialized) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (globelOtel!= null)

* Returns the priority order for this resource provider.
*/
@Override
public int order() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the order()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants