Skip to content

Conversation

@yvz5
Copy link
Contributor

@yvz5 yvz5 commented Jan 14, 2026

Summary by CodeRabbit

  • New Features
    • Telemetry and metrics now include service version and environment name for richer traces and metrics.
    • Instrumentation is environment-aware, enabling context-specific logging and telemetry.
    • Service metadata and an environment attribute are added to exported traces/metrics for better filtering and observability.
    • ASP.NET, HTTP client, and runtime instrumentation with OTLP exporting remain enabled.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 14, 2026

Walkthrough

Startup now passes ApiVersion and the current environment name into OpenTelemetry setup. The monitoring extension accepts service version and environment, builds an OpenTelemetry Resource with serviceName/serviceVersion and adds an "environment" attribute, then continues registering instrumentation and OTLP exporter as before.

Changes

Cohort / File(s) Change Summary
Bootstrap / Startup
src/Simplic.OxS.Server/Bootstrap.cs
Passes ApiVersion and CurrentEnvironment.EnvironmentName into AddLoggingAndMetricTracing; adds OpenTelemetry.Metrics and OpenTelemetry.Resources imports; minor formatting around the instrumentation call.
Monitoring extension
src/Simplic.OxS.Server/Extensions/MonitoringExtension.cs
Updates AddLoggingAndMetricTracing signature to accept serviceVersion and environmentName; configures Resource with AddService(serviceName: ..., serviceVersion: ...), calls AddTelemetrySdk(), and adds an "environment" attribute via resource.AddAttributes(...); instrumentation and exporter wiring unchanged.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application Startup
    participant Bootstrap as Bootstrap.cs
    participant Monitoring as MonitoringExtension
    participant OTEL as OpenTelemetry SDK
    participant Collector as OTLP Collector

    App->>Bootstrap: start, obtain ApiVersion and CurrentEnvironment.EnvironmentName
    Bootstrap->>Monitoring: AddLoggingAndMetricTracing(serviceName, serviceVersion, environmentName)
    Monitoring->>OTEL: Build Resource (serviceName, serviceVersion) and Add "environment" attribute
    Monitoring->>OTEL: Register instrumentations (ASP.NET Core, HttpClient, Runtime) and OTLP exporter
    OTEL->>Collector: Export traces/metrics via OTLP
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code with whiskers bright,

I stitched a version and an env just right,
Metrics hum softly, traces take flight,
OTLP sends the day's small delight,
A rabbit's cheer for telemetry tonight.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title mentions enabling OTLP metrics, but the actual changes focus on adding environment-aware instrumentation parameters (ApiVersion and EnvironmentName) to the logging and metric tracing setup. Clarify whether the PR's primary goal is enabling OTLP metrics by default or adding environment-aware instrumentation parameters. Consider a more specific title like 'Add environment-aware instrumentation to logging and metrics' if the latter is the main change.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/Simplic.OxS.Server/Bootstrap.cs`:
- Around line 161-181: The AddOpenTelemetry() block in Bootstrap.cs is
duplicating metrics/instrumentation already registered by
AddLoggingAndMetricTracing(); remove the duplicate AddOpenTelemetry() call and
its chained ConfigureResource/WithMetrics configuration from Bootstrap.cs, or
alternatively move any unique configuration (e.g., resource attributes like
serviceName/serviceVersion/serviceInstanceId or adding the "environment"
attribute) into the existing AddLoggingAndMetricTracing() /
MonitoringExtension.cs implementation so instrumentation
(AddAspNetCoreInstrumentation, AddHttpClientInstrumentation,
AddRuntimeInstrumentation, AddOtlpExporter) is only registered once.
🧹 Nitpick comments (3)
src/Simplic.OxS.Server/Bootstrap.cs (3)

157-158: Use the injected CurrentEnvironment instead of re-reading the environment variable.

CurrentEnvironment.EnvironmentName is already available and used at line 54. This avoids redundant environment variable access and maintains consistency.

Suggested change
-            var stage = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";
-            if (stage == "Staging")
+            if (CurrentEnvironment.IsStaging())

If you still need the stage variable for the attribute:

-            var stage = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";
+            var stage = CurrentEnvironment.EnvironmentName;
             if (stage == "Staging")

160-166: Consider handling empty ServiceName defensively.

ServiceName is abstract so it won't be null, but it could be an empty string. The null-coalescing operator won't catch that case.

Suggested change
-                var appName = ServiceName ?? "unset";
+                var appName = string.IsNullOrWhiteSpace(ServiceName) ? "unset" : ServiceName;

168-171: Hardcoded "environment" attribute value doesn't match the variable.

The stage variable is used in the condition check, but the attribute value is hardcoded as "Staging". While functionally equivalent in this context (since it's inside the if (stage == "Staging") block), using the variable would be more maintainable if this pattern expands to other environments.

Suggested change
                     // Add stage to ALL metrics
                     r.AddAttributes([
-                        new KeyValuePair<string, object>("environment", stage)
+                        new KeyValuePair<string, object>("environment", CurrentEnvironment.EnvironmentName)
                     ]);
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f58b4e7 and 4914132.

📒 Files selected for processing (1)
  • src/Simplic.OxS.Server/Bootstrap.cs
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-26T05:52:00.195Z
Learnt from: CR
Repo: simplic/simplic-oxs-storage-management PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-26T05:52:00.195Z
Learning: Applies to {Program.cs,**/Middleware/**/*.cs,**/Logging/**/*.cs,**/Telemetry/**/*.cs} : Use structured logging (e.g., Serilog), appropriate log levels, Application Insights integration, custom telemetry and correlation IDs; monitor performance, errors, usage

Applied to files:

  • src/Simplic.OxS.Server/Bootstrap.cs
📚 Learning: 2025-11-26T09:38:34.885Z
Learnt from: CR
Repo: simplic/simplic-oxs-accounting PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-26T09:38:34.885Z
Learning: Use built-in ASP.NET Core features when possible before introducing third-party dependencies

Applied to files:

  • src/Simplic.OxS.Server/Bootstrap.cs
🔇 Additional comments (2)
src/Simplic.OxS.Server/Bootstrap.cs (2)

15-16: LGTM on imports.

The OpenTelemetry imports are appropriate for the metrics configuration being added.


156-182: PR title says "enable otlp metrics by default" but metrics are only enabled for Staging.

The implementation restricts OpenTelemetry metrics to only the Staging environment. If this is intentional (gradual rollout), consider updating the PR description to clarify. If metrics should be enabled more broadly, the condition logic needs adjustment.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/Simplic.OxS.Server/Extensions/MonitoringExtension.cs`:
- Around line 39-56: The ConfigureResource block is missing the serviceVersion,
causing tracing/metrics to lack it; update the ConfigureResource call inside
AddOpenTelemetry to include the serviceVersion in its AddService invocation
(e.g., call AddService(serviceName: $"oxs-{serviceName}", serviceVersion:
serviceVersion) or pass the previously built resourceBuilder into
AddOpenTelemetry) so that resourceBuilder and ConfigureResource are consistent
and tracing/metrics include the same serviceVersion as logging.
♻️ Duplicate comments (1)
src/Simplic.OxS.Server/Bootstrap.cs (1)

157-182: Remove duplicate OpenTelemetry configuration; this block duplicates instrumentation already registered by AddLoggingAndMetricTracing().

As noted in a previous review, AddLoggingAndMetricTracing() (line 63) already configures OpenTelemetry with the same metrics instrumentation (AddAspNetCoreInstrumentation, AddHttpClientInstrumentation, AddRuntimeInstrumentation) in MonitoringExtension.cs. This second AddOpenTelemetry() call creates duplicate metric collection and export.

Additionally, line 157 redundantly reads ASPNETCORE_ENVIRONMENT when CurrentEnvironment.EnvironmentName is already available and passed to AddLoggingAndMetricTracing().

If Staging-specific behavior is needed (e.g., always enabling OTLP export), integrate that logic into MonitoringExtension.cs rather than duplicating the entire OpenTelemetry setup.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4914132 and 5a4aa2b.

📒 Files selected for processing (2)
  • src/Simplic.OxS.Server/Bootstrap.cs
  • src/Simplic.OxS.Server/Extensions/MonitoringExtension.cs
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-26T05:52:00.195Z
Learnt from: CR
Repo: simplic/simplic-oxs-storage-management PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-26T05:52:00.195Z
Learning: Applies to {Program.cs,**/Middleware/**/*.cs,**/Logging/**/*.cs,**/Telemetry/**/*.cs} : Use structured logging (e.g., Serilog), appropriate log levels, Application Insights integration, custom telemetry and correlation IDs; monitor performance, errors, usage

Applied to files:

  • src/Simplic.OxS.Server/Extensions/MonitoringExtension.cs
  • src/Simplic.OxS.Server/Bootstrap.cs
📚 Learning: 2025-11-26T09:38:34.885Z
Learnt from: CR
Repo: simplic/simplic-oxs-accounting PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-26T09:38:34.885Z
Learning: Use built-in ASP.NET Core features when possible before introducing third-party dependencies

Applied to files:

  • src/Simplic.OxS.Server/Bootstrap.cs
🔇 Additional comments (3)
src/Simplic.OxS.Server/Bootstrap.cs (2)

15-16: LGTM!

The OpenTelemetry namespace imports are correctly added to support the new metrics configuration.


61-63: LGTM!

Correctly passes the ApiVersion and CurrentEnvironment.EnvironmentName to the updated AddLoggingAndMetricTracing method signature, enabling environment-aware telemetry configuration.

src/Simplic.OxS.Server/Extensions/MonitoringExtension.cs (1)

27-27: LGTM!

The updated method signature appropriately accepts serviceVersion and environmentName parameters to enable version-aware and environment-aware telemetry configuration.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@yvz5 yvz5 merged commit 673b9db into master Jan 22, 2026
2 checks passed
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.

3 participants