Skip to content
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
4 changes: 4 additions & 0 deletions samples/dapr/ServiceA/DaprServiceA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\ServiceDefaults\ServiceDefaults.csproj" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions samples/dapr/ServiceA/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
Expand Down
4 changes: 4 additions & 0 deletions samples/dapr/ServiceB/DaprServiceB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\ServiceDefaults\ServiceDefaults.csproj" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions samples/dapr/ServiceB/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
Expand Down
6 changes: 5 additions & 1 deletion src/Aspire.Dashboard/Otlp/Model/OtlpApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public OtlpApplication(Resource resource, IReadOnlyDictionary<string, OtlpApplic
}
if (string.IsNullOrEmpty(InstanceId))
{
throw new ArgumentException("Resource needs to include a 'service.instance.id'");
//
// NOTE: The service.instance.id value is a recommended attribute, but not required.
// See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#service-experimental
//
InstanceId = ApplicationName;
}
Suffix = applications.Where(a => a.Value.ApplicationName == ApplicationName).Count();
_logger = logger;
Expand Down
12 changes: 11 additions & 1 deletion src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,26 @@ public static class OtlpHelpers
{
public static string? GetServiceId(this Resource resource)
{
string? serviceName = null;

for (var i = 0; i < resource.Attributes.Count; i++)
{
var attribute = resource.Attributes[i];
if (attribute.Key == OtlpApplication.SERVICE_INSTANCE_ID)
{
return attribute.Value.GetString();
}
if (attribute.Key == OtlpApplication.SERVICE_NAME)
{
serviceName = attribute.Value.GetString();
}
}

return null;
//
// NOTE: The service.instance.id value is a recommended attribute, but not required.
// See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#service-experimental
//
return serviceName;
}

public static string ToShortenedId(string id) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Lifecycle;
using Microsoft.Extensions.Configuration;
using System.Globalization;
using System.Net.Sockets;
using static Aspire.Hosting.Dapr.CommandLineArgs;
Expand All @@ -11,6 +12,7 @@ namespace Aspire.Hosting.Dapr;

internal sealed class DaprDistributedApplicationLifecycleHook : IDistributedApplicationLifecycleHook
{
private readonly IConfiguration _configuration;
private readonly DaprOptions _options;
private readonly DaprPortManager _portManager;

Expand All @@ -20,9 +22,12 @@ internal sealed class DaprDistributedApplicationLifecycleHook : IDistributedAppl
: Path.Combine("/usr", "local", "bin", "dapr");

private const int DaprHttpPortStartRange = 50001;
private const string DashboardOtlpUrlVariableName = "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL";
private const string DashboardOtlpUrlDefaultValue = "http://localhost:18889";

public DaprDistributedApplicationLifecycleHook(DaprOptions options, DaprPortManager portManager)
public DaprDistributedApplicationLifecycleHook(IConfiguration configuration, DaprOptions options, DaprPortManager portManager)
{
_configuration = configuration;
this._options = options;
this._portManager = portManager;
}
Expand Down Expand Up @@ -126,6 +131,27 @@ public Task BeforeStartAsync(DistributedApplicationModel appModel, CancellationT
component.Annotations.Add(new NameAnnotation { Name = sidecarOptions?.AppId ?? "Unknown" });
component.Annotations.AddRange(ports.Select(port => new ServiceBindingAnnotation(ProtocolType.Tcp, name: port.Key, port: port.Value.Port)));

// NOTE: Telemetry is enabled by default.
if (this._options.EnableTelemetry != false)
{
component.Annotations.Add(
new EnvironmentCallbackAnnotation(
env =>
{

//
// NOTE: Setting OTEL_EXPORTER_OTLP_ENDPOINT will not override any explicit OTLP configuration in a specified Dapr sidecar configuration file.
// The ambient Dapr sidecar configuration file does not configure an OTLP exporter (but could have been updated by the user to do so).
//
// TODO: It would be nice, at some point, to consolidate determination of the OTLP endpoint as it's now repeated in a few places.
//

env["OTEL_EXPORTER_OTLP_ENDPOINT"] = this._configuration[DashboardOtlpUrlVariableName] ?? DashboardOtlpUrlDefaultValue;
env["OTEL_EXPORTER_OTLP_INSECURE"] = "true";
env["OTEL_EXPORTER_OTLP_PROTOCOL"] = "grpc";
}));
}

component.Annotations.Add(
new ExecutableArgsCallbackAnnotation(
updatedArgs =>
Expand Down
8 changes: 8 additions & 0 deletions src/Aspire.Hosting.Dapr/DaprOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ public sealed record DaprOptions
/// Gets or sets the path to the Dapr CLI.
/// </summary>
public string? DaprPath { get; init; }

/// <summary>
/// Gets or sets whether Dapr sidecars export telemetry to the Aspire dashboard.
/// </summary>
/// <remarks>
/// Telemetry is enabled by default.
/// </remarks>
public bool? EnableTelemetry { get; init; }
}