Skip to content

Commit 42f41cf

Browse files
authored
Enable CORS for with OTLP HTTP endpoint and add playground app (#5212)
1 parent 0d8b294 commit 42f41cf

File tree

34 files changed

+2413
-23
lines changed

34 files changed

+2413
-23
lines changed

Aspire.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.NodeJs.Tests
569569
EndProject
570570
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.RabbitMQ.Tests", "tests\Aspire.Hosting.RabbitMQ.Tests\Aspire.Hosting.RabbitMQ.Tests.csproj", "{872AC635-B880-4FAC-BB43-4FD97D7B1209}"
571571
EndProject
572+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BrowserTelemetry", "BrowserTelemetry", "{15966C27-17FA-4A46-A172-55985411540A}"
573+
EndProject
574+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserTelemetry.AppHost", "playground\BrowserTelemetry\BrowserTelemetry.AppHost\BrowserTelemetry.AppHost.csproj", "{29946391-F2E9-4DEA-92A2-6FAAC1508446}"
575+
EndProject
576+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserTelemetry.Web", "playground\BrowserTelemetry\BrowserTelemetry.Web\BrowserTelemetry.Web.csproj", "{091EA540-355B-4763-9980-5F83F0BB6F11}"
577+
EndProject
572578
Global
573579
GlobalSection(SolutionConfigurationPlatforms) = preSolution
574580
Debug|Any CPU = Debug|Any CPU
@@ -1499,6 +1505,14 @@ Global
14991505
{872AC635-B880-4FAC-BB43-4FD97D7B1209}.Debug|Any CPU.Build.0 = Debug|Any CPU
15001506
{872AC635-B880-4FAC-BB43-4FD97D7B1209}.Release|Any CPU.ActiveCfg = Release|Any CPU
15011507
{872AC635-B880-4FAC-BB43-4FD97D7B1209}.Release|Any CPU.Build.0 = Release|Any CPU
1508+
{29946391-F2E9-4DEA-92A2-6FAAC1508446}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1509+
{29946391-F2E9-4DEA-92A2-6FAAC1508446}.Debug|Any CPU.Build.0 = Debug|Any CPU
1510+
{29946391-F2E9-4DEA-92A2-6FAAC1508446}.Release|Any CPU.ActiveCfg = Release|Any CPU
1511+
{29946391-F2E9-4DEA-92A2-6FAAC1508446}.Release|Any CPU.Build.0 = Release|Any CPU
1512+
{091EA540-355B-4763-9980-5F83F0BB6F11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1513+
{091EA540-355B-4763-9980-5F83F0BB6F11}.Debug|Any CPU.Build.0 = Debug|Any CPU
1514+
{091EA540-355B-4763-9980-5F83F0BB6F11}.Release|Any CPU.ActiveCfg = Release|Any CPU
1515+
{091EA540-355B-4763-9980-5F83F0BB6F11}.Release|Any CPU.Build.0 = Release|Any CPU
15021516
EndGlobalSection
15031517
GlobalSection(SolutionProperties) = preSolution
15041518
HideSolutionNode = FALSE
@@ -1773,6 +1787,9 @@ Global
17731787
{1419BDCB-47EB-43EB-9149-C935B7208A72} = {90A70EFA-F26A-49E0-A375-DB461E4E0E25}
17741788
{50450FBB-CD10-4281-B22C-7FF86CEE9D9F} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
17751789
{872AC635-B880-4FAC-BB43-4FD97D7B1209} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
1790+
{15966C27-17FA-4A46-A172-55985411540A} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
1791+
{29946391-F2E9-4DEA-92A2-6FAAC1508446} = {15966C27-17FA-4A46-A172-55985411540A}
1792+
{091EA540-355B-4763-9980-5F83F0BB6F11} = {15966C27-17FA-4A46-A172-55985411540A}
17761793
EndGlobalSection
17771794
GlobalSection(ExtensibilityGlobals) = postSolution
17781795
SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<IsAspireHost>true</IsAspireHost>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<Compile Include="..\..\KnownResourceNames.cs" Link="KnownResourceNames.cs" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<AspireProjectOrPackageReference Include="Aspire.Hosting.AppHost" />
17+
<ProjectReference Include="..\BrowserTelemetry.Web\BrowserTelemetry.Web.csproj" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
var builder = DistributedApplication.CreateBuilder(args);
5+
6+
builder.AddProject<Projects.BrowserTelemetry_Web>("web")
7+
.WithExternalHttpEndpoints();
8+
9+
// This project is only added in playground projects to support development/debugging
10+
// of the dashboard. It is not required in end developer code. Comment out this code
11+
// to test end developer dashboard launch experience. Refer to Directory.Build.props
12+
// for the path to the dashboard binary (defaults to the Aspire.Dashboard bin output
13+
// in the artifacts dir).
14+
builder.AddProject<Projects.Aspire_Dashboard>(KnownResourceNames.AspireDashboard);
15+
16+
builder.Build().Run();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"https": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "https://localhost:15887;http://localhost:15888",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"DOTNET_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "https://localhost:16175",
13+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:17037",
14+
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
15+
}
16+
},
17+
"http": {
18+
"commandName": "Project",
19+
"dotnetRunMessages": true,
20+
"launchBrowser": true,
21+
"applicationUrl": "http://localhost:15888",
22+
"environmentVariables": {
23+
"ASPNETCORE_ENVIRONMENT": "Development",
24+
"DOTNET_ENVIRONMENT": "Development",
25+
"DOTNET_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "http://localhost:16175",
26+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:17037",
27+
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
28+
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
29+
}
30+
},
31+
"generate-manifest": {
32+
"commandName": "Project",
33+
"launchBrowser": true,
34+
"dotnetRunMessages": true,
35+
"commandLineArgs": "--publisher manifest --output-path aspire-manifest.json",
36+
"applicationUrl": "http://localhost:15888",
37+
"environmentVariables": {
38+
"ASPNETCORE_ENVIRONMENT": "Development",
39+
"DOTNET_ENVIRONMENT": "Development",
40+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175"
41+
}
42+
}
43+
}
44+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning",
6+
"Aspire.Hosting.Dcp": "Warning"
7+
}
8+
}
9+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\Playground.ServiceDefaults\Playground.ServiceDefaults.csproj" />
11+
</ItemGroup>
12+
13+
<Target Name="NpmInstall" Inputs="package.json" Outputs="node_modules/.install-stamp">
14+
<!--
15+
Use npm install or npm ci depending on RestorePackagesWithLockFile value.
16+
Uncomment the following lines if you want to use this feature:
17+
18+
<PropertyGroup>
19+
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
20+
</PropertyGroup>
21+
-->
22+
<Exec Command="npm ci" Condition="'$(RestorePackagesWithLockFile)' == 'true'" />
23+
<Exec Command="npm install" Condition="'$(RestorePackagesWithLockFile)' != 'true'" />
24+
25+
<!-- Write the stamp file, so incremental builds work -->
26+
<Touch Files="node_modules/.install-stamp" AlwaysCreate="true" />
27+
</Target>
28+
29+
<!--
30+
2. Run npm run build before building the .NET project.
31+
MSBuild runs NpmInstall before this task because of the DependsOnTargets attribute.
32+
-->
33+
<Target Name="NpmRunBuild" DependsOnTargets="NpmInstall" BeforeTargets="BeforeBuild" Condition="'$(Configuration)' == 'Debug' ">
34+
<Exec Command="npm run build" />
35+
</Target>
36+
37+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@page
2+
<div class="container">
3+
<p>Hello world</p>
4+
</div>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.AspNetCore.Mvc.RazorPages;
2+
3+
namespace BrowserTelemetry.Web.Pages;
4+
5+
public class IndexModel : PageModel
6+
{
7+
private readonly ILogger<IndexModel> _logger;
8+
9+
public IndexModel(ILogger<IndexModel> logger)
10+
{
11+
_logger = logger;
12+
}
13+
14+
public void OnGet()
15+
{
16+
17+
}
18+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@using System.Diagnostics
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>@ViewData["Title"] - BrowserTelemetry</title>
8+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
9+
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
10+
11+
@if (Activity.Current is { } currentActivity)
12+
{
13+
<meta name="traceparent" content="@currentActivity.Id" />
14+
}
15+
</head>
16+
<body>
17+
<header>
18+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
19+
<div class="container">
20+
<a class="navbar-brand" asp-area="" asp-page="/Index">BrowserTelemetry</a>
21+
</div>
22+
</nav>
23+
</header>
24+
<div class="container">
25+
<main role="main" class="pb-3">
26+
@RenderBody()
27+
</main>
28+
</div>
29+
@await RenderSectionAsync("Scripts", required: false)
30+
<script src="scripts/bundle.js"></script>
31+
@if (Environment.GetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT") is { Length: > 0 } endpointUrl)
32+
{
33+
var headers = Environment.GetEnvironmentVariable("OTEL_EXPORTER_OTLP_HEADERS");
34+
var attributes = Environment.GetEnvironmentVariable("OTEL_RESOURCE_ATTRIBUTES");
35+
<script>
36+
BrowserTelemetry.initializeTelemetry('@endpointUrl', '@headers', '@attributes');
37+
</script>
38+
}
39+
</body>
40+
</html>

0 commit comments

Comments
 (0)