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

Native AOT support and assembly scanning enhancements #221

Merged
merged 12 commits into from
Feb 25, 2025
Merged
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: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**/.dockerignore
**/.dockerignore
**/.env
**/.gitignore
**/.project
Expand Down
9 changes: 7 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ resharper_redundant_case_label_highlighting=do_not_show
resharper_redundant_argument_default_value_highlighting=do_not_show
resharper_explicit_caller_info_argument_highlighting=hint

dotnet_diagnostic.IDE0057.severity = none
dotnet_diagnostic.IL3050.severity = error
dotnet_diagnostic.IL2026.severity = error

[examples/Example.AspNetCore.WebApiAot/*.cs]
dotnet_diagnostic.IL3050.severity = none
dotnet_diagnostic.IL2026.severity = none

[*.{sh,bat,ps1}]
trim_trailing_whitespace=true
Expand All @@ -203,4 +208,4 @@ insert_final_newline=true
end_of_line = lf

[{LICENSE,NOTICE}]
end_of_line = lf
end_of_line = lf
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- name: Build and Push Profiler Docker Image
id: docker-push
continue-on-error: true # continue for now until we see it working in action
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991 # v6.13.0
uses: docker/build-push-action@0adf9959216b96bec444f325f1e493d4aa344497 # v6.14.0
with:
cache-from: type=gha
cache-to: type=gha,mode=max
Expand Down
26 changes: 25 additions & 1 deletion Elastic.OpenTelemetry.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34321.82
Expand Down Expand Up @@ -54,6 +54,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "k8s", "k8s", "{21E61166-264
examples\k8s\README.md = examples\k8s\README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.AspNetCore.WebApiAot", "examples\Example.AspNetCore.WebApiAot\Example.AspNetCore.WebApiAot.csproj", "{D985352F-6741-4BB2-8BBC-38A69F624D26}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "applications", "applications", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi", "test-applications\WebApi\WebApi.csproj", "{2A1F61D6-EE54-4ECE-9814-A2BF34957415}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiDotNet8", "test-applications\WebApiDotNet8\WebApiDotNet8\WebApiDotNet8.csproj", "{C8C543F8-5C7A-4748-A3E8-658D79E3FDC1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -120,6 +128,18 @@ Global
{B1CA9165-89D9-4D6E-AFEF-5434A8D8A672}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1CA9165-89D9-4D6E-AFEF-5434A8D8A672}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1CA9165-89D9-4D6E-AFEF-5434A8D8A672}.Release|Any CPU.Build.0 = Release|Any CPU
{D985352F-6741-4BB2-8BBC-38A69F624D26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D985352F-6741-4BB2-8BBC-38A69F624D26}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D985352F-6741-4BB2-8BBC-38A69F624D26}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D985352F-6741-4BB2-8BBC-38A69F624D26}.Release|Any CPU.Build.0 = Release|Any CPU
{2A1F61D6-EE54-4ECE-9814-A2BF34957415}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A1F61D6-EE54-4ECE-9814-A2BF34957415}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A1F61D6-EE54-4ECE-9814-A2BF34957415}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A1F61D6-EE54-4ECE-9814-A2BF34957415}.Release|Any CPU.Build.0 = Release|Any CPU
{C8C543F8-5C7A-4748-A3E8-658D79E3FDC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C8C543F8-5C7A-4748-A3E8-658D79E3FDC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8C543F8-5C7A-4748-A3E8-658D79E3FDC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8C543F8-5C7A-4748-A3E8-658D79E3FDC1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -138,6 +158,10 @@ Global
{782E4DC1-8186-4BAC-B2F4-89E6DF22A4DD} = {AAD39891-0B70-47FA-A212-43E1AAE5DF56}
{B1CA9165-89D9-4D6E-AFEF-5434A8D8A672} = {E622CFF2-C6C4-40FB-BE42-7C4F2B38B75A}
{21E61166-2640-4E38-8108-1BA510C07110} = {4E95C87B-655B-4BC3-8F2A-DF06B7AAB7E9}
{D985352F-6741-4BB2-8BBC-38A69F624D26} = {4E95C87B-655B-4BC3-8F2A-DF06B7AAB7E9}
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {AAD39891-0B70-47FA-A212-43E1AAE5DF56}
{2A1F61D6-EE54-4ECE-9814-A2BF34957415} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{C8C543F8-5C7A-4748-A3E8-658D79E3FDC1} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {573B2B5F-8CBB-4D52-A55A-4E65E282AAFB}
Expand Down
5 changes: 3 additions & 2 deletions Elastic.OpenTelemetry.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ See the LICENSE file in the project root for more information</s:String>
&lt;/Entry.Match&gt;&#xD;
&lt;Entry.SortBy&gt;&#xD;
&lt;Kind Is="Member" /&gt;&#xD;
&lt;Name Is="Enter Pattern Here" /&gt;&#xD;
&lt;Name /&gt;&#xD;
&lt;/Entry.SortBy&gt;&#xD;
&lt;/Entry&gt;&#xD;
&lt;Entry DisplayName="Readonly Fields"&gt;&#xD;
Expand All @@ -294,7 +294,7 @@ See the LICENSE file in the project root for more information</s:String>
&lt;Entry.SortBy&gt;&#xD;
&lt;Access /&gt;&#xD;
&lt;Readonly /&gt;&#xD;
&lt;Name Is="Enter Pattern Here" /&gt;&#xD;
&lt;Name /&gt;&#xD;
&lt;/Entry.SortBy&gt;&#xD;
&lt;/Entry&gt;&#xD;
&lt;Entry DisplayName="Constructors"&gt;&#xD;
Expand Down Expand Up @@ -570,6 +570,7 @@ See the LICENSE file in the project root for more information</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002EMemberReordering_002EMigrations_002ECSharpFileLayoutPatternRemoveIsAttributeUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/HighlightingManager/HighlightingEnabledByDefault/@EntryValue">False</s:Boolean>
Expand Down
1 change: 0 additions & 1 deletion examples/AppHost/README.md
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

2 changes: 1 addition & 1 deletion examples/Example.AspNetCore.Mvc/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
Expand Down
25 changes: 4 additions & 21 deletions examples/Example.AspNetCore.Mvc/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,31 @@
// See the LICENSE file in the project root for more information

using OpenTelemetry;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

var builder = WebApplication.CreateBuilder(args);

using var loggerFactory = LoggerFactory.Create(loggingBuilder => loggingBuilder
.SetMinimumLevel(LogLevel.Trace)
.AddConsole());

var logger = loggerFactory.CreateLogger("OpenTelemetry");

// Add services to the container.
builder.Services
.AddHttpClient()
.AddElasticOpenTelemetry(builder.Configuration, logger)
.ConfigureResource(r => r.AddService("MyNewService1"));

//builder.Services.AddOpenTelemetry()
// .ConfigureResource(r => r.AddService("MyNewService2"))
// .WithElasticDefaults(builder.Configuration);

//OpenTelemetrySdk.Create(b => b.WithElasticDefaults(builder.Configuration));
.AddElasticOpenTelemetry()
.WithTracing(t => t.AddAspNetCoreInstrumentation()); // This is redundant but used in manual testing for now

builder.Services
.AddControllersWithViews();

var app = builder.Build();

app.Logger.LogInformation("Process Id {ProcesId}", Environment.ProcessId);
app.Logger.LogInformation("Process Id {ProcessId}", Environment.ProcessId);

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapControllerRoute(
Expand Down
2 changes: 1 addition & 1 deletion examples/Example.AspNetCore.Mvc/Views/E2E/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@{
@{
ViewData["Title"] = "Home Page";
}

Expand Down
2 changes: 1 addition & 1 deletion examples/Example.AspNetCore.Mvc/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@{
@{
ViewData["Title"] = "Home Page";
}

Expand Down
2 changes: 1 addition & 1 deletion examples/Example.AspNetCore.Mvc/Views/Home/Privacy.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@{
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>
Expand Down
2 changes: 1 addition & 1 deletion examples/Example.AspNetCore.Mvc/Views/Shared/Error.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ErrorViewModel
@model ErrorViewModel
@{
ViewData["Title"] = "Error";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
for details on configuring this project to bundle and minify static web assets. */

a.navbar-brand {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
2 changes: 1 addition & 1 deletion examples/Example.AspNetCore.Mvc/Views/_ViewStart.cshtml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@{
@{
Layout = "_Layout";
}
2 changes: 1 addition & 1 deletion examples/Example.AspNetCore.Mvc/wwwroot/js/site.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
// Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
// for details on configuring this project to bundle and minify static web assets.

// Write your JavaScript code.
13 changes: 13 additions & 0 deletions examples/Example.AspNetCore.WebApiAot/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "9.0.2",
"commands": [
"dotnet-ef"
],
"rollForward": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<PublishAot>true</PublishAot>
<UserSecretsId>205c18a1-356e-4e59-b15f-2a297cb8d4b8</UserSecretsId>
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.11.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Elastic.OpenTelemetry\Elastic.OpenTelemetry.csproj" />
<TrimmerRootAssembly Include="Elastic.OpenTelemetry" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@Example.AspNetCore.WebApiAot_HostAddress = http://localhost:5283

GET {{Example.AspNetCore.WebApiAot_HostAddress}}/todos/
Accept: application/json

###

GET {{Example.AspNetCore.WebApiAot_HostAddress}}/todos/1
Accept: application/json

###
42 changes: 42 additions & 0 deletions examples/Example.AspNetCore.WebApiAot/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using OpenTelemetry;
using OpenTelemetry.Trace;

var builder = WebApplication.CreateSlimBuilder(args);

builder.AddElasticOpenTelemetry(b => b.WithTracing(t => t.AddAspNetCoreInstrumentation()));

builder.Services.ConfigureHttpJsonOptions(options =>
{
options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
});

var app = builder.Build();

var sampleTodos = new Todo[] {
new(1, "Walk the dog"),
new(2, "Do the dishes", DateOnly.FromDateTime(DateTime.Now)),
new(3, "Do the laundry", DateOnly.FromDateTime(DateTime.Now.AddDays(1))),
new(4, "Clean the bathroom"),
new(5, "Clean the car", DateOnly.FromDateTime(DateTime.Now.AddDays(2)))
};

var todosApi = app.MapGroup("/todos");
todosApi.MapGet("/", () => sampleTodos);
todosApi.MapGet("/{id}", (int id) =>
sampleTodos.FirstOrDefault(a => a.Id == id) is { } todo
? Results.Ok(todo)
: Results.NotFound());

app.Run();

[SuppressMessage("Design", "CA1050:Declare types in namespaces")]
public record Todo(int Id, string? Title, DateOnly? DueBy = null, bool IsComplete = false);

[JsonSerializable(typeof(Todo[]))]
internal partial class AppJsonSerializerContext : JsonSerializerContext;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "todos",
"applicationUrl": "http://localhost:5283",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
15 changes: 15 additions & 0 deletions examples/Example.AspNetCore.WebApiAot/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Elastic": {
"OpenTelemetry": {
"LogLevel": "Trace",
"LogDirectory": "C:\\Logs\\AotLogs"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
4 changes: 2 additions & 2 deletions examples/Example.MinimalApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information

using System.Diagnostics;
using Example.Api;
using Example.MinimalApi;
using OpenTelemetry;

var builder = WebApplication.CreateBuilder(args);
Expand All @@ -27,7 +27,7 @@

app.Run();

namespace Example.Api
namespace Example.MinimalApi
{
internal static class Api
{
Expand Down
2 changes: 2 additions & 0 deletions examples/ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
using OpenTelemetry.Trace;

// ReSharper disable once CheckNamespace
#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace Microsoft.Extensions.Hosting;
#pragma warning restore IDE0130 // Namespace does not match folder structure

public static class Extensions
{
Expand Down
Loading
Loading