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

Implement synchronous gauge APIs for Double and Long types #670

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

batuhansk
Copy link
Contributor

This PR introduces support for synchronous gauges in the OpenTelemetry Swift SDK, complementing the existing observable gauge functionality.

Key Changes:

  1. New Protocols:

    • Added DoubleGauge and LongGauge protocols to define synchronous gauge behavior.
    • Extended DoubleGaugeBuilder and LongGaugeBuilder with build() methods for synchronous gauges.
  2. SDK Implementation:

    • Implemented DoubleGaugeSdk and LongGaugeSdk classes to handle synchronous gauge recording.
    • Updated DoubleGaugeBuilderSdk and LongGaugeBuilderSdk to support building synchronous gauges.
  3. No-op Implementations:

    • Added NoopDoubleGauge and NoopLongGauge for default no-op behavior.
  4. Testing:

    • Added unit tests to verify synchronous gauge functionality in BuilderTests and StableMeterProviderTests.
    • Updated example usage in main.swift to demonstrate both observable and synchronous gauges.

Example Usage:

// Synchronous gauge
var gauge = meter.gaugeBuilder(name: "my_gauge").build()
gauge.record(value: 1.0, attributes: ["test": AttributeValue.bool(true)])

// Observable gauge
var observableGauge = meter.gaugeBuilder(name: "my_observable_gauge").buildWithCallback { measurement in
    measurement.record(value: 1.0)
}

- Implemented DoubleGauge and LongGauge protocols for synchronous gauge recording
- Added build() methods to DoubleGaugeBuilder and LongGaugeBuilder
- Introduced DoubleGaugeSdk and LongGaugeSdk implementations
- Updated unit tests to verify synchronous gauge functionality
- Added example usage in sample code
- Maintained backward compatibility with existing asynchronous gauge API

This change provides developers with more flexibility in metric collection by supporting both synchronous and asynchronous gauge patterns, aligning with OpenTelemetry specifications.
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.

1 participant