add aspire for otel

This commit is contained in:
Matt Parker
2025-09-29 19:07:38 +10:00
parent b7029e7dce
commit e0ddcc55f2
16 changed files with 358 additions and 1 deletions

View File

@@ -46,6 +46,12 @@
<PackageVersion Include="R3" Version="1.3.0" /> <PackageVersion Include="R3" Version="1.3.0" />
<PackageVersion Include="XtermBlazor" Version="2.1.2" /> <PackageVersion Include="XtermBlazor" Version="2.1.2" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Aspire">
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.12.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.12.0" />
</ItemGroup>
<ItemGroup Label="Pinned Transitive Dependencies"> <ItemGroup Label="Pinned Transitive Dependencies">
<PackageVersion Include="Microsoft.CodeAnalysis.ExternalAccess.Razor.Features" Version="5.0.0-2.25465.103" /> <PackageVersion Include="Microsoft.CodeAnalysis.ExternalAccess.Razor.Features" Version="5.0.0-2.25465.103" />
<PackageVersion Include="Microsoft.CodeAnalysis.Remote.ServiceHub" Version="5.0.0-2.25465.103" /> <PackageVersion Include="Microsoft.CodeAnalysis.Remote.ServiceHub" Version="5.0.0-2.25465.103" />

View File

@@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.props = Directory.Build.props Directory.Build.props = Directory.Build.props
global.json = global.json global.json = global.json
README.md = README.md README.md = README.md
Directory.Packages.props = Directory.Packages.props
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpIDE.Photino", "src\SharpIDE.Photino\SharpIDE.Photino.csproj", "{E35167E1-0FF4-4194-97A8-CC95EDA224CD}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpIDE.Photino", "src\SharpIDE.Photino\SharpIDE.Photino.csproj", "{E35167E1-0FF4-4194-97A8-CC95EDA224CD}"
@@ -24,6 +25,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Roslyn.Benchmarks", "tests\
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpIDE.RazorAccess", "src\SharpIDE.RazorAccess\SharpIDE.RazorAccess.csproj", "{0DE5B721-4C17-4A93-A94B-5DEA9CAAAE99}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpIDE.RazorAccess", "src\SharpIDE.RazorAccess\SharpIDE.RazorAccess.csproj", "{0DE5B721-4C17-4A93-A94B-5DEA9CAAAE99}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{DABBDFD2-C631-439C-9ACB-EDDF659D5257}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCoreServiceDefaults", "tools\AspNetCoreServiceDefaults\AspNetCoreServiceDefaults.csproj", "{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppHost", "tools\AppHost\AppHost.csproj", "{CF00AC9C-F796-4C23-8D69-370F494999D7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpIDE.Godot", "src\SharpIDE.Godot\SharpIDE.Godot.csproj", "{D306410D-3A28-4F1B-A09B-CA10041A7C53}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -82,6 +91,42 @@ Global
{0DE5B721-4C17-4A93-A94B-5DEA9CAAAE99}.Release|x64.Build.0 = Release|Any CPU {0DE5B721-4C17-4A93-A94B-5DEA9CAAAE99}.Release|x64.Build.0 = Release|Any CPU
{0DE5B721-4C17-4A93-A94B-5DEA9CAAAE99}.Release|x86.ActiveCfg = Release|Any CPU {0DE5B721-4C17-4A93-A94B-5DEA9CAAAE99}.Release|x86.ActiveCfg = Release|Any CPU
{0DE5B721-4C17-4A93-A94B-5DEA9CAAAE99}.Release|x86.Build.0 = Release|Any CPU {0DE5B721-4C17-4A93-A94B-5DEA9CAAAE99}.Release|x86.Build.0 = Release|Any CPU
{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E}.Debug|x64.ActiveCfg = Debug|Any CPU
{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E}.Debug|x64.Build.0 = Debug|Any CPU
{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E}.Debug|x86.ActiveCfg = Debug|Any CPU
{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E}.Debug|x86.Build.0 = Debug|Any CPU
{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E}.Release|Any CPU.Build.0 = Release|Any CPU
{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E}.Release|x64.ActiveCfg = Release|Any CPU
{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E}.Release|x64.Build.0 = Release|Any CPU
{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E}.Release|x86.ActiveCfg = Release|Any CPU
{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E}.Release|x86.Build.0 = Release|Any CPU
{CF00AC9C-F796-4C23-8D69-370F494999D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF00AC9C-F796-4C23-8D69-370F494999D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF00AC9C-F796-4C23-8D69-370F494999D7}.Debug|x64.ActiveCfg = Debug|Any CPU
{CF00AC9C-F796-4C23-8D69-370F494999D7}.Debug|x64.Build.0 = Debug|Any CPU
{CF00AC9C-F796-4C23-8D69-370F494999D7}.Debug|x86.ActiveCfg = Debug|Any CPU
{CF00AC9C-F796-4C23-8D69-370F494999D7}.Debug|x86.Build.0 = Debug|Any CPU
{CF00AC9C-F796-4C23-8D69-370F494999D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF00AC9C-F796-4C23-8D69-370F494999D7}.Release|Any CPU.Build.0 = Release|Any CPU
{CF00AC9C-F796-4C23-8D69-370F494999D7}.Release|x64.ActiveCfg = Release|Any CPU
{CF00AC9C-F796-4C23-8D69-370F494999D7}.Release|x64.Build.0 = Release|Any CPU
{CF00AC9C-F796-4C23-8D69-370F494999D7}.Release|x86.ActiveCfg = Release|Any CPU
{CF00AC9C-F796-4C23-8D69-370F494999D7}.Release|x86.Build.0 = Release|Any CPU
{D306410D-3A28-4F1B-A09B-CA10041A7C53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D306410D-3A28-4F1B-A09B-CA10041A7C53}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D306410D-3A28-4F1B-A09B-CA10041A7C53}.Debug|x64.ActiveCfg = Debug|Any CPU
{D306410D-3A28-4F1B-A09B-CA10041A7C53}.Debug|x64.Build.0 = Debug|Any CPU
{D306410D-3A28-4F1B-A09B-CA10041A7C53}.Debug|x86.ActiveCfg = Debug|Any CPU
{D306410D-3A28-4F1B-A09B-CA10041A7C53}.Debug|x86.Build.0 = Debug|Any CPU
{D306410D-3A28-4F1B-A09B-CA10041A7C53}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{D306410D-3A28-4F1B-A09B-CA10041A7C53}.Release|Any CPU.Build.0 = Debug|Any CPU
{D306410D-3A28-4F1B-A09B-CA10041A7C53}.Release|x64.ActiveCfg = Debug|Any CPU
{D306410D-3A28-4F1B-A09B-CA10041A7C53}.Release|x64.Build.0 = Debug|Any CPU
{D306410D-3A28-4F1B-A09B-CA10041A7C53}.Release|x86.ActiveCfg = Debug|Any CPU
{D306410D-3A28-4F1B-A09B-CA10041A7C53}.Release|x86.Build.0 = Debug|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@@ -91,5 +136,8 @@ Global
{D7D5D39E-DA3A-4B10-8F40-B07B769347F4} = {F4ED837F-888A-4D01-BCED-C360B9CE0865} {D7D5D39E-DA3A-4B10-8F40-B07B769347F4} = {F4ED837F-888A-4D01-BCED-C360B9CE0865}
{252CE098-2F9A-4DA3-A172-EE1167B335BF} = {B6835010-35FA-4C74-AB48-009FB923185D} {252CE098-2F9A-4DA3-A172-EE1167B335BF} = {B6835010-35FA-4C74-AB48-009FB923185D}
{0DE5B721-4C17-4A93-A94B-5DEA9CAAAE99} = {F4ED837F-888A-4D01-BCED-C360B9CE0865} {0DE5B721-4C17-4A93-A94B-5DEA9CAAAE99} = {F4ED837F-888A-4D01-BCED-C360B9CE0865}
{C54A5E24-8F16-413F-87F1-BD5E57D2AC1E} = {DABBDFD2-C631-439C-9ACB-EDDF659D5257}
{CF00AC9C-F796-4C23-8D69-370F494999D7} = {DABBDFD2-C631-439C-9ACB-EDDF659D5257}
{D306410D-3A28-4F1B-A09B-CA10041A7C53} = {F4ED837F-888A-4D01-BCED-C360B9CE0865}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@@ -1,4 +1,5 @@
using Ardalis.GuardClauses; using System.Diagnostics;
using Ardalis.GuardClauses;
using Microsoft.VisualStudio.SolutionPersistence.Model; using Microsoft.VisualStudio.SolutionPersistence.Model;
using Microsoft.VisualStudio.SolutionPersistence.Serializer; using Microsoft.VisualStudio.SolutionPersistence.Serializer;
@@ -9,6 +10,7 @@ public static class IntermediateMapper
internal static async Task<IntermediateSolutionModel> GetIntermediateModel(string solutionFilePath, internal static async Task<IntermediateSolutionModel> GetIntermediateModel(string solutionFilePath,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
using var _ = SharpIdeOtel.Source.StartActivity();
var serializer = SolutionSerializers.GetSerializerByMoniker(solutionFilePath); var serializer = SolutionSerializers.GetSerializerByMoniker(solutionFilePath);
Guard.Against.Null(serializer, nameof(serializer)); Guard.Against.Null(serializer, nameof(serializer));
var vsSolution = await serializer.OpenAsync(solutionFilePath, cancellationToken); var vsSolution = await serializer.OpenAsync(solutionFilePath, cancellationToken);

View File

@@ -6,6 +6,7 @@ public static class VsPersistenceMapper
{ {
public static async Task<SharpIdeSolutionModel> GetSolutionModel(string solutionFilePath, CancellationToken cancellationToken = default) public static async Task<SharpIdeSolutionModel> GetSolutionModel(string solutionFilePath, CancellationToken cancellationToken = default)
{ {
using var _ = SharpIdeOtel.Source.StartActivity();
var timer = Stopwatch.StartNew(); var timer = Stopwatch.StartNew();
// This intermediate model is pretty much useless, but I have left it around as we grab the project nodes with it, which we might use later. // This intermediate model is pretty much useless, but I have left it around as we grab the project nodes with it, which we might use later.
var intermediateModel = await IntermediateMapper.GetIntermediateModel(solutionFilePath, cancellationToken); var intermediateModel = await IntermediateMapper.GetIntermediateModel(solutionFilePath, cancellationToken);

View File

@@ -0,0 +1,10 @@
using System.Diagnostics;
using System.Diagnostics.Metrics;
namespace SharpIDE.Application;
public static class SharpIdeOtel
{
public static readonly ActivitySource Source = new("SharpIde");
public static readonly Meter Meter = new("SharpIde");
}

View File

@@ -9,6 +9,8 @@ public partial class IdeDiagnosticsPanel : Control
{ {
_graphEdit = GetNode<GraphEdit>("%GraphEdit"); _graphEdit = GetNode<GraphEdit>("%GraphEdit");
//_graphEdit.ConnectionRequest += GraphEditOnConnectionRequest; //_graphEdit.ConnectionRequest += GraphEditOnConnectionRequest;
//var graphNode = GetNode<Node>("%GraphNode");
} }
// private void GraphEditOnConnectionRequest(StringName fromNode, long fromPort, StringName toNode, long toPort) // private void GraphEditOnConnectionRequest(StringName fromNode, long fromPort, StringName toNode, long toPort)

View File

@@ -1,5 +1,6 @@
using Godot; using Godot;
using Microsoft.Build.Locator; using Microsoft.Build.Locator;
using Microsoft.Extensions.Hosting;
using SharpIDE.Application.Features.Analysis; using SharpIDE.Application.Features.Analysis;
using SharpIDE.Application.Features.SolutionDiscovery; using SharpIDE.Application.Features.SolutionDiscovery;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
@@ -30,6 +31,7 @@ public partial class IdeRoot : Control
public override void _Ready() public override void _Ready()
{ {
MSBuildLocator.RegisterDefaults(); MSBuildLocator.RegisterDefaults();
GodotServiceDefaults.AddServiceDefaults();
_openSlnButton = GetNode<Button>("%OpenSlnButton"); _openSlnButton = GetNode<Button>("%OpenSlnButton");
_buildSlnButton = GetNode<Button>("%BuildSlnButton"); _buildSlnButton = GetNode<Button>("%BuildSlnButton");

View File

@@ -6,6 +6,7 @@
<ImplicitUsings>true</ImplicitUsings> <ImplicitUsings>true</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\tools\AspNetCoreServiceDefaults\AspNetCoreServiceDefaults.csproj" PrivateAssets="all" />
<ProjectReference Include="..\SharpIDE.Application\SharpIDE.Application.csproj" /> <ProjectReference Include="..\SharpIDE.Application\SharpIDE.Application.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

13
tools/AppHost/AppHost.cs Normal file
View File

@@ -0,0 +1,13 @@
using AppHost;
using Projects;
var builder = DistributedApplication.CreateBuilder(args);
//var photino = builder.AddProject<SharpIDE_Photino>("photino");
builder.AddGodot("../../src/SharpIDE.Godot/SharpIDE.Godot.csproj", "sharpide-godot")
.WithOtlpExporter();
var appHost = builder.Build();
await appHost.RunAsync();

View File

@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="Aspire.AppHost.Sdk" Version="9.5.0"/>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>c8b6b3c2-8acc-412d-9d58-38b990d2f79f</UserSecretsId>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.5.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,156 @@
using Aspire.Hosting.Lifecycle;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace AppHost;
// https://github.com/maddymontaquila/Godot-SnakeCS/blob/maddy/aspire/AppHost/GodotExtensions.cs
public static class GodotExtensions
{
/// <summary>
/// Adds a Godot project to the application model.
/// </summary>
/// <param name="builder">The distributed application builder.</param>
/// <param name="projectPath">The path to the Godot project file (.godot).</param>
/// <param name="name">The name of the resource.</param>
/// <param name="args">Optional arguments to pass to the Godot executable.</param>
/// <returns>A reference to the Godot project resource.</returns>
public static IResourceBuilder<ExecutableResource> AddGodot(
this IDistributedApplicationBuilder builder,
string projectPath,
string? name = null,
params string[] args)
{
name ??= Path.GetFileNameWithoutExtension(projectPath);
var projectDirectory = Path.GetDirectoryName(projectPath) ?? ".";
var godotPath = GetGodotExecutablePath();
// Build the arguments list
var arguments = new List<string>
{
"--path",
projectDirectory,
//"--verbose"
};
// Add any custom args
arguments.AddRange(args);
// Create a standard ExecutableResource (since custom ones don't seem to work well)
var godotResource = builder.AddExecutable(
name: name,
command: godotPath,
workingDirectory: projectDirectory,
args: arguments.ToArray());
//.WithEnvironment("OTEL_EXPORTER_OTLP_ENDPOINT", Environment.GetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT") ?? throw new InvalidOperationException("OTEL_EXPORTER_OTLP_ENDPOINT environment variable is not set"));
// Add a lifecycle hook to handle building before startup
builder.Services.AddSingleton<IDistributedApplicationLifecycleHook>(sp =>
new GodotBuildHook(
projectPath,
projectDirectory,
sp.GetRequiredService<ILogger<GodotBuildHook>>()));
return godotResource;
}
/// <summary>
/// Gets the Godot executable path based on the current platform.
/// </summary>
private static string GetGodotExecutablePath()
{
// First check for GODOT environment variable
var godotPath = Environment.GetEnvironmentVariable("GODOT");
if (!string.IsNullOrWhiteSpace(godotPath))
{
return godotPath;
}
// Fallback to platform-specific defaults
if (OperatingSystem.IsMacOS())
{
return "godot";
}
else if (OperatingSystem.IsWindows())
{
return "godot.exe";
}
else if (OperatingSystem.IsLinux())
{
return "godot";
}
throw new PlatformNotSupportedException("Current platform is not supported for Godot execution.");
}
/// <summary>
/// Lifecycle hook to build the Godot project before launching
/// </summary>
private class GodotBuildHook : IDistributedApplicationLifecycleHook
{
private readonly string _projectPath;
private readonly string _projectDirectory;
private readonly ILogger<GodotBuildHook> _logger;
public GodotBuildHook(string projectPath, string projectDirectory, ILogger<GodotBuildHook> logger)
{
_projectPath = projectPath;
_projectDirectory = projectDirectory;
_logger = logger;
}
public async Task BeforeStartAsync(DistributedApplicationModel appModel, CancellationToken cancellationToken = default)
{
_logger.LogInformation("Building Godot project: {ProjectPath}", _projectPath);
// Execute dotnet build on the project
var buildProcess = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"build \"{_projectPath}\" --configuration Debug",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
WorkingDirectory = _projectDirectory
}
};
buildProcess.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
_logger.LogInformation("[Godot Build] {Data}", e.Data);
}
};
buildProcess.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
_logger.LogError("[Godot Build] {Data}", e.Data);
}
};
buildProcess.Start();
buildProcess.BeginOutputReadLine();
buildProcess.BeginErrorReadLine();
await buildProcess.WaitForExitAsync(cancellationToken);
if (buildProcess.ExitCode != 0)
{
_logger.LogError("Failed to build Godot project: {ProjectPath}", _projectPath);
return;
}
_logger.LogInformation("Successfully built Godot project: {ProjectPath}", _projectPath);
}
public Task AfterStartAsync(DistributedApplicationModel appModel, CancellationToken cancellationToken = default)
{
return Task.CompletedTask;
}
}
}

View File

@@ -0,0 +1,18 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17042",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21295",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22130",
"GODOT": "C:/Users/Matthew/Documents/Godot/4.5/Godot_v4.5-stable_mono_win64.exe"
}
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}

View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,45 @@
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
namespace Microsoft.Extensions.Hosting;
public static class GodotServiceDefaults
{
private static TracerProvider _tracerProvider;
private static MeterProvider _meterProvider;
public static void AddServiceDefaults()
{
var endpoint = Environment.GetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT");
if (endpoint is null)
{
Console.WriteLine("OTEL_EXPORTER_OTLP_ENDPOINT is not set, skipping OpenTelemetry setup.");
return;
}
var endpointUri = new Uri(endpoint!);
var resource = ResourceBuilder.CreateDefault()
.AddService("sharpide-godot");
_tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetResourceBuilder(resource)
.AddSource("SharpIde")
.AddOtlpExporter(options =>
{
options.Endpoint = endpointUri;
options.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc;
})
.Build();
_meterProvider = Sdk.CreateMeterProviderBuilder()
.SetResourceBuilder(resource)
.AddMeter("SharpIde")
.AddRuntimeInstrumentation()
.AddOtlpExporter(options =>
{
options.Endpoint = endpointUri;
options.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc;
})
.Build();
}
}