Skip to content

Commit 315186b

Browse files
committed
Don't create release version of C3D.Extensions.SystemWeb.OpenTelemetry.Application
1 parent 2fbbda4 commit 315186b

File tree

5 files changed

+53
-19
lines changed

5 files changed

+53
-19
lines changed

samples/WaitForOutput/AspireWaitForConsoleOutput.AppHost/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ private static void Main(string[] args)
2020
.WaitFor(sqldb!)
2121
)
2222
.WithOutputWatcher(GetMagic(), true, "magic")
23+
.CreateReferenceExpression("magic", out var magicNumber)
2324
.OnMatched((o, c) =>
2425
{
2526
var logger = o.ServiceProvider.GetRequiredService<ILogger<Program>>();
@@ -38,9 +39,10 @@ private static void Main(string[] args)
3839

3940
// The GetMagic Regex will capture the magic number from the console app output and store it as a property
4041
// The output string will be of the format "{number} is the magic number!"
41-
// Once it is detected, we can store it in a ReferenceExpression to be used as an environment variable in the next project
42+
// Once it is detected, we can retrieve it using a ReferenceExpression, as an environment variable in the next project
4243

43-
var magicNumber = console.GetReferenceExpression("magic");
44+
// The fluent CreateReferenceExpression method above is just a shortcut for
45+
// var magicNumber = console.GetReferenceExpression("magic");
4446

4547
// webapp won't start until console has output the message "Ready Now..."
4648
// Note that 'console' does not have to exit, it just has to output the message

src/C3D/Extensions/Aspire/OutputWatcher/Annotations/OutputWatcherRegExAnnotation.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,37 @@ public OutputWatcherRegExAnnotation(
1818

1919
public override string PredicateName => matcher.ToString();
2020

21-
public Func<OutputWatcherRegExAnnotation, ValueTask<string?>> ValueFunc { get; set; } =
22-
static async (annotation) =>
21+
public Func<OutputWatcherRegExAnnotation, ValueTask<string?>> ValueFunc { get; set; } =
22+
static async annotation =>
2323
await Task.FromResult(annotation.properties["Match"]?.ToString());
2424

2525
public async ValueTask<string?> GetValueAsync(CancellationToken cancellationToken = default) => await ValueFunc(this);
2626

27+
public Func<Group, KeyValuePair<string, object>?> GroupValueFunc { get; set; } =
28+
static group => new(group.Name, group.Value);
29+
2730
public override bool IsMatch(string message)
2831
{
29-
if (matcher.IsMatch(message))
32+
var match = matcher.Match(message);
33+
if (match.Success)
3034
{
31-
properties["Match"] = matcher.Match(message).Value;
32-
foreach (var groupName in matcher.GetGroupNames())
35+
properties["Match"] = match.Value;
36+
foreach (Group group in match.Groups)
3337
{
34-
properties[groupName] = matcher.Match(message).Groups[groupName].Value;
38+
var kvp = GroupValueFunc(group);
39+
if (kvp is not null)
40+
{
41+
if (kvp.Value.Value is null)
42+
{
43+
properties.Remove(kvp.Value.Key);
44+
}
45+
else
46+
{
47+
properties[kvp.Value.Key] = kvp.Value.Value;
48+
}
49+
}
3550
}
3651
}
37-
return matcher.IsMatch(message);
52+
return match.Success;
3853
}
3954
}

src/C3D/Extensions/Aspire/OutputWatcher/Extensions/OutputWatcherExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ public static ReferenceExpression GetReferenceExpression<TResource, TAnnotation>
106106
where TAnnotation : OutputWatcherRegExAnnotation
107107
=> ReferenceExpression.Create($"{builder.GetValueProvider(property, formatter)}");
108108

109+
public static OutputWatcherBuilder<TResource, TAnnotation> CreateReferenceExpression<TResource, TAnnotation>(this
110+
OutputWatcherBuilder<TResource, TAnnotation> builder,
111+
string property,
112+
out ReferenceExpression referenceExpression,
113+
Func<object?, ValueTask<string?>>? formatter = null)
114+
where TResource : IResource
115+
where TAnnotation : OutputWatcherRegExAnnotation
116+
{
117+
referenceExpression = builder.GetReferenceExpression(property, formatter);
118+
return builder;
119+
}
120+
109121
public static OutputWatcherBuilder<TResource, TAnnotation> OnMatched<TResource, TAnnotation>(this
110122
OutputWatcherBuilder<TResource, TAnnotation> builder,
111123
Func<OutputMatchedEvent, CancellationToken, Task> matchedAction)

src/C3D/Extensions/SystemWeb/OpenTelemetry/Application/C3D.Extensions.SystemWeb.OpenTelemetry.Application.csproj

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@
66
<AssemblyTitle>$(AssemblyTitle) System.Web OpenTelemetry HttpApplication</AssemblyTitle>
77
</PropertyGroup>
88

9+
<PropertyGroup>
10+
<OpenTelemetryVersion>1.12.0</OpenTelemetryVersion>
11+
<OpenTelemetryBetaVersion>1.12.0-beta.1</OpenTelemetryBetaVersion>
12+
</PropertyGroup>
13+
914
<ItemGroup Label="OpenTelemetry">
1015
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
1116

12-
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.11.2" />
13-
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.2" />
17+
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="$(OpenTelemetryVersion)" />
18+
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="$(OpenTelemetryVersion)" />
1419

15-
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.11.1" />
16-
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.11.1" />
20+
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="$(OpenTelemetryVersion)" />
21+
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="$(OpenTelemetryVersion)" />
1722

18-
<PackageReference Include="OpenTelemetry.Instrumentation.AspNet" Version="1.11.0-beta.2" />
19-
<PackageReference Include="OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule" Version="1.11.0-beta.2" />
23+
<PackageReference Include="OpenTelemetry.Instrumentation.AspNet" Version="$(OpenTelemetryBetaVersion)" />
24+
<PackageReference Include="OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule" Version="$(OpenTelemetryBetaVersion)" />
2025
</ItemGroup>
2126

2227
<PropertyGroup>

src/C3D/Extensions/SystemWeb/OpenTelemetry/Application/version.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"../Directory.Build.props",
77
"../Directory.Build.targets"
88
],
9-
"publicReleaseRefSpec": [
10-
"^refs/heads/main$", // we release out of main
11-
"^refs/heads/rel/v\\d+\\.\\d+" // we also release tags starting with rel/N.N
12-
],
9+
//"publicReleaseRefSpec": [
10+
// "^refs/heads/main$", // we release out of main
11+
// "^refs/heads/rel/v\\d+\\.\\d+" // we also release tags starting with rel/N.N
12+
//],
1313
"nugetPackageVersion": {
1414
"semVer": 2
1515
},

0 commit comments

Comments
 (0)