Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ the release.
([#2614](https://github.com/open-telemetry/opentelemetry-demo/pull/2614))
* [grafana] Update grafana version to 12.2.0
([#2615](https://github.com/open-telemetry/opentelemetry-demo/pull/2615))
* [feat] Flexible database selection
([#2645](https://github.com/open-telemetry/opentelemetry-demo/pull/2645))

## 2.1.3

Expand Down
48 changes: 48 additions & 0 deletions docker-compose-mongo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# docker-compose-mongo.yml
# Use: docker compose -f docker-compose.yml -f docker-compose-mongo.yml up

x-default-logging: &logging
driver: "json-file"
options:
max-size: "5m"
max-file: "2"
tag: "{{.Name}}"

services:
# 1. Remove the Postgres service
postgresql: !reset null

# 2. Add the MongoDB service
mongo:
image: mongo:7
Copy link
Member

Choose a reason for hiding this comment

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

I would consider pinning it by the SHA for security reasons, but it should be probably done across the repository. Here it can stay as is.

container_name: mongo
restart: unless-stopped
environment:
MONGO_INITDB_DATABASE: otel
MONGO_INITDB_ROOT_USERNAME: otelu
MONGO_INITDB_ROOT_PASSWORD: otelp
OTEL_DOTNET_AUTO_INSTRUMENTATION_MONGODB_ENABLED: true
ports:
- "27017:27017"
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 10s
timeout: 5s
retries: 5
logging: *logging
networks:
- default

# 3. Configure 'accounting' service for MongoDB
accounting:
environment:
- DB_TYPE=mongo
- DB_CONNECTION_STRING=mongodb://otelu:otelp@mongo:27017/otel?authSource=admin
depends_on:
postgresql: !reset []
otel-collector:
condition: service_started
kafka:
condition: service_healthy
mongo:
condition: service_healthy
58 changes: 58 additions & 0 deletions docker-compose-mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# This is a Docker Compose override file to switch the demo from PostgreSQL to MySQL.
# To use it, run:
# docker compose -f docker-compose.yml -f docker-compose-mysql.yml up

# Use the same default logging as the base file
x-default-logging: &logging
driver: "json-file"
options:
max-size: "5m"
max-file: "2"
tag: "{{.Name}}"

services:
# 1. Remove the Postgres service defined in the base file.
# The `!reset null` syntax completely removes the service.
postgresql: !reset null

# 2. Add the MySQL service.
mysql:
image: mysql:8
# The platform is important for users on ARM-based machines (e.g., Apple M1/M2).
# For x86/amd64 machines, you can remove this line.
platform: linux/arm64
container_name: mysql
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: otelp
MYSQL_DATABASE: otel
MYSQL_USER: otelu
MYSQL_PASSWORD: otelp
ports:
- "3306:3306"
# A healthcheck ensures other services only start after MySQL is ready.
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
logging: *logging
networks:
- default

# 3. Override the 'accounting' service to use MySQL.
accounting:
environment:
# Set the DB_TYPE to trigger the MySQL logic in your code.
- DB_TYPE=mysql
# IMPORTANT: Use the correct key-value pair format for the Pomelo driver.
- DB_CONNECTION_STRING=Server=mysql;Port=3306;Database=otel;User=otelu;Password=otelp;
depends_on:
postgresql: !reset []
otel-collector:
condition: service_started
kafka:
condition: service_healthy
# Add a dependency on the new mysql service and wait for it to be healthy.
mysql:
condition: service_healthy
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ services:
restart: unless-stopped
environment:
- KAFKA_ADDR
- DB_TYPE=postgres
- OTEL_EXPORTER_OTLP_ENDPOINT=http://${OTEL_COLLECTOR_HOST}:${OTEL_COLLECTOR_PORT_HTTP}
- OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE
- OTEL_RESOURCE_ATTRIBUTES
Expand Down
61 changes: 33 additions & 28 deletions src/accounting/Accounting.csproj
Copy link
Member

Choose a reason for hiding this comment

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

have checkout locally your code. Your goal should be to avoid downgrades (especially in AutoInstrumentation) and utilize secure versions of packages

Please consider following versions as the goal. It is compiling, but I didn't check if it gives expected results.

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Confluent.Kafka" Version="2.12.0" />
        <PackageReference Include="EFCore.NamingConventions" Version="9.0.0" />
        <PackageReference Include="Google.Protobuf" Version="3.32.1" />
        <PackageReference Include="Grpc.Tools" Version="2.68.1">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.9" />
        <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
        <PackageReference Include="MongoDB.Driver" Version="3.5.0" />
        <PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="2.1.0" />
        <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
        <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
        <PackageReference Include="OpenTelemetry.AutoInstrumentation" Version="1.12.0" />
    </ItemGroup>

    <ItemGroup>
        <!-- GrpcServices is 'none' so that we do not need to depend on the grpc nuget package, and we only need protobuf support. -->
        <Protobuf Include="src/protos/demo.proto" GrpcServices="none" />
    </ItemGroup>

    <ItemGroup>
      <Folder Include="src\protos\" />
    </ItemGroup>

</Project>

Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<!-- ADDED: Suppress the security audit warning that is failing the build -->
<NoWarn>$(NoWarn);NU1903</NoWarn>
Comment on lines +9 to +10
Copy link
Member

Choose a reason for hiding this comment

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

This is very bad practice to mute security errors. Especially in the demonstrating objects.

</PropertyGroup>

<ItemGroup>
<PackageReference Include="Confluent.Kafka" Version="2.11.0" />
<PackageReference Include="EFCore.NamingConventions" Version="9.0.0" />
<PackageReference Include="Google.Protobuf" Version="3.31.1" />
<PackageReference Include="Grpc.Tools" Version="2.68.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.7" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
<PackageReference Include="OpenTelemetry.AutoInstrumentation" Version="1.12.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Confluent.Kafka" Version="2.11.0" />
<PackageReference Include="EFCore.NamingConventions" Version="8.0.3" />
<PackageReference Include="Google.Protobuf" Version="3.31.1" />
<PackageReference Include="Grpc.Tools" Version="2.68.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
<PackageReference Include="MongoDB.Driver" Version="3.0.0" />
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="2.1.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
<PackageReference Include="OpenTelemetry.AutoInstrumentation" Version="1.9.0" />
Copy link
Member

Choose a reason for hiding this comment

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

This is the second change which is stopper to me. Demo is designed in this way, that is should work with the latest version of AutoInstrumentaiton. In case of any issues, please let me know what is wrong here.

</ItemGroup>

<ItemGroup>
<!-- GrpcServices is 'none' so that we do not need to depend on the grpc nuget package, and we only need protobuf support. -->
<Protobuf Include="src\protos\demo.proto" GrpcServices="none" />
</ItemGroup>
<ItemGroup>
<!-- GrpcServices is 'none' so that we do not need to depend on the grpc nuget package, and we only need protobuf support. -->
<Protobuf Include="src/protos/demo.proto" GrpcServices="none" />
</ItemGroup>

<ItemGroup>
<Folder Include="src\protos\" />
</ItemGroup>
<ItemGroup>
<Folder Include="src\protos\" />
</ItemGroup>

</Project>
</Project>
Loading