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

feat(service): configure opentelemetry #1342

Merged
merged 3 commits into from
Oct 29, 2024
Merged

Conversation

arealmaas
Copy link
Collaborator

@arealmaas arealmaas commented Oct 24, 2024

Description

Configures opentelemetry for Service. Copy pasta from WebAPI.

Dependent on #1341

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • Documentation is updated (either in docs-directory, Altinnpedia or a separate linked PR in altinn-studio-docs., if applicable)

Summary by CodeRabbit

  • New Features

    • Enhanced logging and telemetry configuration during application startup.
    • Introduced a modular approach to configuring telemetry settings.
  • Bug Fixes

    • Improved error handling during application startup to ensure exceptions are logged appropriately.
  • Refactor

    • Updated method signature for improved telemetry configuration handling.
    • Removed direct call to Application Insights, streamlining telemetry integration.

Copy link
Contributor

coderabbitai bot commented Oct 24, 2024

📝 Walkthrough

Walkthrough

The pull request introduces changes to the Digdir.Domain.Dialogporten.Service project, specifically modifying the project file to remove the package reference for Microsoft.ApplicationInsights.AspNetCore version 2.22.0. Additionally, the Program.cs file has been updated to enhance logging and telemetry configuration by introducing a new TelemetryConfiguration variable and modifying the BuildAndRun method to accept this configuration as a parameter. The changes aim to improve the structure and clarity of telemetry integration within the application.

Changes

File Path Change Summary
src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj Removed package reference for Microsoft.ApplicationInsights.AspNetCore version 2.22.0.
src/Digdir.Domain.Dialogporten.Service/Program.cs Updated BuildAndRun method to accept TelemetryConfiguration parameter; enhanced logging setup with a new telemetry configuration variable; removed direct call to AddApplicationInsightsTelemetry().

Possibly related PRs

Suggested reviewers

  • knuhau
  • MagnusSandgren

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@arealmaas arealmaas marked this pull request as ready for review October 24, 2024 13:13
@arealmaas arealmaas requested a review from a team as a code owner October 24, 2024 13:13
Copy link

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

🧹 Outside diff range and nitpick comments (2)
src/Digdir.Domain.Dialogporten.Service/Program.cs (2)

Line range hint 38-48: Update logger configuration to use OpenTelemetry

The logger configuration still depends on ApplicationInsights, but should be updated to use OpenTelemetry based on the PR objectives.

Would you like me to provide an example of how to configure Serilog with OpenTelemetry? This would include:

  1. Adding appropriate OpenTelemetry packages
  2. Configuring Serilog with OpenTelemetry sink
  3. Setting up proper telemetry export

Line range hint 15-67: Consider separating telemetry configuration

To improve maintainability and separation of concerns, consider:

  1. Moving telemetry configuration to a separate extension class
  2. Using configuration patterns that allow for different telemetry providers
  3. Adding telemetry sampling configuration for production environments

This would make it easier to:

  • Switch between different telemetry providers
  • Configure different sampling rates per environment
  • Test telemetry integration
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fa3157a and 70e2750.

📒 Files selected for processing (2)
  • src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj (0 hunks)
  • src/Digdir.Domain.Dialogporten.Service/Program.cs (4 hunks)
💤 Files with no reviewable changes (1)
  • src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj
🔇 Additional comments (2)
src/Digdir.Domain.Dialogporten.Service/Program.cs (2)

Line range hint 24-36: LGTM!

The error handling is robust and the telemetryConfiguration parameter passing is consistent.


66-67: Verify OpenTelemetry configuration implementation

The ConfigureTelemetry() extension method is called, but we need to verify its implementation.

✅ Verification successful

Let me gather more context about the telemetry configuration implementation.


Based on the implementation found, I can now provide the final response:

OpenTelemetry configuration follows best practices

The ConfigureTelemetry() implementation in AspNetUtilitiesExtensions.cs demonstrates a well-structured OpenTelemetry setup that:

  • Configures service name and resource attributes
  • Implements proper instrumentation for ASP.NET Core and HTTP clients
  • Includes PostgreSQL tracing
  • Adds runtime metrics instrumentation
  • Handles both Azure Monitor (production) and Application Insights (development) appropriately
  • Implements smart sampling in non-development environments
  • Excludes health check endpoints from tracing
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for ConfigureTelemetry implementation
ast-grep --pattern 'public static $_$ ConfigureTelemetry(this $_$ builder) {
  $$$
}'

# Check for OpenTelemetry configuration patterns
rg -A 5 'AddOpenTelemetry|ConfigureOpenTelemetry'

Length of output: 1386


Script:

#!/bin/bash
# Search for the complete ConfigureTelemetry implementation
ast-grep --pattern 'ConfigureTelemetry'

# Look for the complete file content to understand the full context
rg -l "ConfigureTelemetry" | xargs cat

Length of output: 15301

@arealmaas arealmaas merged commit 513d5e4 into main Oct 29, 2024
24 checks passed
@arealmaas arealmaas deleted the feat/use-open-telemetry-service branch October 29, 2024 09:26
arealmaas added a commit that referenced this pull request Oct 29, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.27.0](v1.26.3...v1.27.0)
(2024-10-29)


### Features

* Add restrictions to Transmissions reference hierarchy
([#1310](#1310))
([e3d53ca](e3d53ca))
* **graphql:** configure opentelemetry
([#1343](#1343))
([e31c08b](e31c08b))
* **infrastructure:** add availability test for apim
([#1327](#1327))
([1f9fa2b](1f9fa2b))
* **service:** configure opentelemetry
([#1342](#1342))
([513d5e4](513d5e4))
* **utils:** configure open telemetry tracing for masstransit in aspnet
package ([#1344](#1344))
([5ec3b84](5ec3b84))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: Are Almaas <arealmaas@gmail.com>
@coderabbitai coderabbitai bot mentioned this pull request Nov 1, 2024
4 tasks
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