Skip to content

[Monitor] Generate exporter with TypeSpec#44442

Merged
hectorhdzg merged 28 commits intoAzure:mainfrom
pvaneck:monitor-otel-exporter-typespec
Mar 6, 2026
Merged

[Monitor] Generate exporter with TypeSpec#44442
hectorhdzg merged 28 commits intoAzure:mainfrom
pvaneck:monitor-otel-exporter-typespec

Conversation

@pvaneck
Copy link
Copy Markdown
Member

@pvaneck pvaneck commented Dec 16, 2025

Generation from TypeSpec from the branch in this PR: Azure/azure-rest-api-specs#38795

Noteable changes

  • The time field in TelemetryItem seems to have always been typed as datetime.datetime, but was being set as a ISO8601 date string. I have adjusted the tests and the _create_telemetry_item method to set the time to a datetime object and have adjusted the tests accordingly. The datetime objects will be serialized to the ISO8601 formatted strings (e.g. 2025-12-15T13:45:30.0000000Z when sent in a request anyway, so this should be fine.
  • In TypeSpec, defaults in models are treated as server-side defaults. The version property in the Domain model has a default of 2, however, the generated code does not include this as a default. The code was updated to explicitly set the version argument when constructing subclasses of Domain.

Notes:

  • Since two different TypeSpec projects are contained in this project (Exporter and LiveMetrics), I am using the batch generation feature of tsp-client where the Exporter project will be emitted into azure/monitor/opentelemetry/exporter/_generated. LiveMetrics will be emitted to azure/monitor/opentelemetry/exporter/_quickpulse/_generated in the future.
  • One test, tests/trace/test_trace.py::TestAzureTraceExporter::test_get_otel_resource_envelope, was failing after the regeneration. It is comparing OTel Resource attributes with MetricsData.properties, but the properties field is type and serialized as Dict[str, str]. Thus, all values end up as strings when checking the values of properties.

Asks for team

  1. Validate whether using datetime objects instead of strings when creating TelemetryItems is acceptable.
  2. Validate whether properties being strings inside MetricsData is acceptable.

@github-actions github-actions bot added the Monitor - Exporter Monitor OpenTelemetry Exporter label Dec 16, 2025
@pvaneck pvaneck force-pushed the monitor-otel-exporter-typespec branch from cd26a71 to b658113 Compare December 16, 2025 21:27
@rads-1996
Copy link
Copy Markdown
Member

@pvaneck I can create a separate PR that runs the black format checks on the existing exporter code. I will share it once it is ready for review.

@pvaneck
Copy link
Copy Markdown
Member Author

pvaneck commented Dec 18, 2025

@rads-1996 Thanks, but I believe it was already formatted with #44462. I just need to rebase off of main.

@pvaneck pvaneck force-pushed the monitor-otel-exporter-typespec branch 4 times, most recently from 8ee495f to 20fc16d Compare January 16, 2026 00:56
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
@pvaneck pvaneck force-pushed the monitor-otel-exporter-typespec branch from 20fc16d to bc3ca46 Compare January 17, 2026 00:22
@hectorhdzg hectorhdzg marked this pull request as ready for review February 6, 2026 23:17
@hectorhdzg hectorhdzg requested a review from lzchen as a code owner February 6, 2026 23:17
Copilot AI review requested due to automatic review settings February 6, 2026 23:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the Azure Monitor OpenTelemetry Exporter’s generated ingestion client/models from the legacy AutoRest output to TypeSpec (tsp-client) output, and updates the hand-written exporter code + tests to align with the new generated surface and serialization behaviors.

Changes:

  • Add TypeSpec batch generation configuration and record TypeSpec source metadata under _generated/.
  • Update exporter implementations/tests to use the new generated module path (_generated.exporter...) and to explicitly set domain schema version.
  • Align telemetry time handling/tests to use datetime objects (and validate properties-as-strings behavior for MetricsData.properties).

Reviewed changes

Copilot reviewed 55 out of 56 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
sdk/monitor/azure-monitor-opentelemetry-exporter/tsp-location.yaml Adds batch generation output configuration for TypeSpec.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/tsp-location.yaml Records the TypeSpec source repo/commit metadata for the generated output.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py Introduces _EXPORTER_DOMAIN_SCHEMA_VERSION used when constructing domain models.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_utils.py Updates telemetry item creation to use datetime for TelemetryItem.time and switches generated model imports.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_base.py Updates storage deserialization/formatting for dpcodegen models and adjusts retry/drop tracking flow.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace/_exporter.py Updates generated imports, normalizes resource properties as Dict[str, str], and sets domain version on data models.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/metrics/_exporter.py Updates generated imports and sets domain version on MetricsData.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/logs/_exporter.py Updates generated imports, sets domain version on log data models, and adjusts tags handling for dpcodegen model semantics.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/customer/_utils.py Updates generated imports to new TypeSpec-generated module path.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_quickpulse/_manager.py Updates generated imports to new TypeSpec-generated module path.
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/trace/test_trace.py Updates imports to new generated path; updates expectations for datetime envelope times; adds JSON-serialization test using SdkJSONEncoder; updates resource attribute expectations to stringified values.
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py Updates import path and adjusts _create_telemetry_item test to expect a datetime time value.
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_exporter.py Updates generated imports; aligns storage formatting tests with dpcodegen model construction; adjusts mock response behavior.
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_base_customer_sdkstats.py Updates generated imports; updates mock response behavior; tightens expectations for track_dropped_items calls.
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/quickpulse/test_manager.py Updates generated imports to new TypeSpec-generated module path.
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/metrics/test_metrics.py Updates imports and changes expected envelope time values to datetime.
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/logs/test_logs.py Updates imports, env var setup, and changes expected envelope time values to datetime.
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/customer_sdk_stats/test_utlities.py Updates generated imports to new TypeSpec-generated module path.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/init.py Repoints _generated.AzureMonitorClient to the new TypeSpec-generated client package.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/apiview-properties.json Adds APIView mapping metadata for the new generated surface.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/_metadata.json Adds generated metadata (e.g., apiVersion).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/operations/_azure_monitor_client_operations.py Removes legacy AutoRest operations mixin (replaced by TypeSpec output).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/aio/operations/_azure_monitor_client_operations.py Removes legacy AutoRest aio operations mixin (replaced by TypeSpec output).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/_azure_monitor_client.py Removes legacy AutoRest client (replaced by TypeSpec output).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/aio/_azure_monitor_client.py Removes legacy AutoRest async client (replaced by TypeSpec output).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/_vendor.py Removes legacy AutoRest vendor request conversion helper.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/_patch.py Removes legacy AutoRest patch hook (replaced by new patch structure under exporter/).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/aio/_patch.py Removes legacy AutoRest aio patch hook (replaced by new patch structure under exporter/aio/).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/models/init.py Removes legacy AutoRest models package init (replaced by TypeSpec output).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/models/_models.py Removes legacy AutoRest models definitions (replaced by TypeSpec output).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/models/_models_py3.py Removes legacy AutoRest py3 models definitions (replaced by TypeSpec output).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/aio/init.py Removes legacy AutoRest aio init (replaced by TypeSpec output).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/init.py Adds new TypeSpec-generated synchronous client package init.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/_client.py Adds new TypeSpec-generated synchronous client implementation.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/_configuration.py Adds new TypeSpec-generated sync configuration handling (including optional credential).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/_operations/init.py Adds new TypeSpec-generated operations package init.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/_operations/_operations.py Adds new TypeSpec-generated sync operations implementation (uses SdkJSONEncoder).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/_patch.py Adds new TypeSpec-generated patch hook for sync client package.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/_utils/init.py Updates generated utils init to TypeSpec generator output.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/_utils/model_base.py Adds dpcodegen model base + SdkJSONEncoder used for serialization/deserialization.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/_utils/utils.py Adds dpcodegen internal typing helper for client mixins.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/_version.py Adds generated version constant for the new client package.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/py.typed Adds PEP 561 marker for the generated package.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/models/init.py Adds new TypeSpec-generated models package init.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/models/_enums.py Adds/updates generated enums (including MonitorDomainKind and Versions).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/models/_patch.py Adds new TypeSpec-generated models patch hook.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/aio/init.py Adds new TypeSpec-generated async client package init.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/aio/_client.py Adds new TypeSpec-generated async client implementation.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/aio/_configuration.py Adds new TypeSpec-generated async configuration handling (including optional credential).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/aio/_operations/init.py Adds new TypeSpec-generated async operations package init.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/aio/_operations/_operations.py Adds new TypeSpec-generated async operations implementation (uses SdkJSONEncoder).
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/aio/_operations/_patch.py Adds new TypeSpec-generated async operations patch hook.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_generated/exporter/aio/_patch.py Adds new TypeSpec-generated async client package patch hook.

Copy link
Copy Markdown
Member

@rads-1996 rads-1996 left a comment

Choose a reason for hiding this comment

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

LGTM

@hectorhdzg hectorhdzg merged commit 5088eec into Azure:main Mar 6, 2026
20 checks passed
aprilk-ms pushed a commit that referenced this pull request Mar 11, 2026
* [Monitor] Generate exporter with TypeSpec

Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>

* Fix resource envelope serialization for OTel resource attributes

* Update tests

* Update log exporter

* Update

* Regenerate exporter typespec models

* Regenerate exporter typespec models and fix renames

* Fix _generated/__init__.py to re-export AzureMonitorClient from exporter subpackage

* Add trailing newline to _generated/__init__.py

* Added tracing false in autogenerated code definition

* Update

* Update

* Remove unused model imports from _base.py and fix lint

* Update tsp-location.yml and regen

Use the merged commit hash from the specs repo and regen using
an updated Python emitter version.

Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>

---------

Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Co-authored-by: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com>
singankit pushed a commit that referenced this pull request Mar 16, 2026
* [Monitor] Generate exporter with TypeSpec

Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>

* Fix resource envelope serialization for OTel resource attributes

* Update tests

* Update log exporter

* Update

* Regenerate exporter typespec models

* Regenerate exporter typespec models and fix renames

* Fix _generated/__init__.py to re-export AzureMonitorClient from exporter subpackage

* Add trailing newline to _generated/__init__.py

* Added tracing false in autogenerated code definition

* Update

* Update

* Remove unused model imports from _base.py and fix lint

* Update tsp-location.yml and regen

Use the merged commit hash from the specs repo and regen using
an updated Python emitter version.

Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>

---------

Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Co-authored-by: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Monitor - Exporter Monitor OpenTelemetry Exporter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants