Skip to content

Commit e7bb24d

Browse files
authored
GraphQL support for 8.0+ (open-telemetry#3615)
1 parent fce3682 commit e7bb24d

File tree

10 files changed

+44
-19
lines changed

10 files changed

+44
-19
lines changed

build/LibraryVersions.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static partial class LibraryVersion
5757
new List<PackageBuildInfo>
5858
{
5959
new("7.5.0", additionalMetaData: new() {{"GraphQLMicrosoftDI","7.5.0"},{"GraphQLServerTransportsAspNetCore","7.5.0"},{"GraphQLServerUIPlayground","7.5.0"}}),
60-
new("7.8.0", additionalMetaData: new() {{"GraphQLMicrosoftDI","7.8.0"},{"GraphQLServerTransportsAspNetCore","7.7.1"},{"GraphQLServerUIPlayground","7.7.1"}}),
60+
new("8.0.2", additionalMetaData: new() {{"GraphQLMicrosoftDI","8.0.2"},{"GraphQLServerTransportsAspNetCore","8.0.2"},{"GraphQLServerUIPlayground","8.0.2"}}),
6161
}
6262
},
6363
{

docs/config.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ due to lack of stable semantic convention.
137137
| `ELASTICSEARCH` | [Elastic.Clients.Elasticsearch](https://www.nuget.org/packages/Elastic.Clients.Elasticsearch) | * \[4\] | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
138138
| `ELASTICTRANSPORT` | [Elastic.Transport](https://www.nuget.org/packages/Elastic.Transport) | ≥0.4.16 | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
139139
| `ENTITYFRAMEWORKCORE` | [Microsoft.EntityFrameworkCore](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore) **Not supported on .NET Framework** | ≥6.0.12 | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
140-
| `GRAPHQL` | [GraphQL](https://www.nuget.org/packages/GraphQL) **Not supported on .NET Framework** | ≥7.5.0 | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
140+
| `GRAPHQL` | [GraphQL](https://www.nuget.org/packages/GraphQL) **Not supported on .NET Framework** | ≥7.5.0 | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
141141
| `GRPCNETCLIENT` | [Grpc.Net.Client](https://www.nuget.org/packages/Grpc.Net.Client) | ≥2.52.0 & < 3.0.0 | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
142142
| `HTTPCLIENT` | [System.Net.Http.HttpClient](https://docs.microsoft.com/dotnet/api/system.net.http.httpclient) and [System.Net.HttpWebRequest](https://docs.microsoft.com/dotnet/api/system.net.httpwebrequest) | * | source | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
143143
| `KAFKA` | [Confluent.Kafka](https://www.nuget.org/packages/Confluent.Kafka) | ≥1.4.0 & < 3.0.0 \[5\] | bytecode | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |

test/Directory.Packages.props

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<PackageVersion Include="Confluent.Kafka" Version="2.5.3" />
77
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
88
<PackageVersion Include="Google.Protobuf" Version="3.28.0" />
9-
<PackageVersion Include="GraphQL" Version="7.8.0" />
10-
<PackageVersion Include="GraphQL.MicrosoftDI" Version="7.8.0" />
11-
<PackageVersion Include="GraphQL.Server.Transports.AspNetCore" Version="7.7.1" />
12-
<PackageVersion Include="GraphQL.Server.Ui.Playground" Version="7.7.1" />
9+
<PackageVersion Include="GraphQL" Version="8.0.2" />
10+
<PackageVersion Include="GraphQL.MicrosoftDI" Version="8.0.2" />
11+
<PackageVersion Include="GraphQL.Server.Transports.AspNetCore" Version="8.0.2" />
12+
<PackageVersion Include="GraphQL.Server.Ui.Playground" Version="8.0.2" />
1313
<PackageVersion Include="Grpc.AspNetCore" Version="2.65.0" />
1414
<PackageVersion Include="Grpc.Net.Client" Version="2.65.0" />
1515
<PackageVersion Include="Grpc.Net.Client.Web" Version="2.65.0" />

test/IntegrationTests/LibraryVersions.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static TheoryData<string> GraphQL
9191
theoryData.Add(string.Empty);
9292
#else
9393
theoryData.Add("7.5.0");
94-
theoryData.Add("7.8.0");
94+
theoryData.Add("8.0.2");
9595
#endif
9696
return theoryData;
9797
}

test/test-applications/integrations/TestApplication.AspNet.NetFramework/Controllers/ValuesController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
// limitations under the License.
1515
// </copyright>
1616

17-
using System.Net.Http;
1817
using System.Net;
18+
using System.Net.Http;
1919
using System.Text;
2020
using System.Web.Http;
2121

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
namespace TestApplication.GraphQL;
5+
6+
/// <summary>
7+
/// Middleware to handle CSRF protection for GraphQL GET requests.
8+
/// GraphQL servers require the "GraphQL-Require-Preflight" header to bypass
9+
/// CSRF checks for GET requests. This middleware adds the header to ensure
10+
/// that GET requests are not blocked due to missing CSRF tokens.
11+
/// </summary>
12+
public class CsrfMiddleware
13+
{
14+
private readonly RequestDelegate _next;
15+
16+
public CsrfMiddleware(RequestDelegate next)
17+
{
18+
_next = next;
19+
}
20+
21+
public async Task InvokeAsync(HttpContext context)
22+
{
23+
context.Request.Headers["GraphQL-Require-Preflight"] = "1";
24+
25+
await _next(context);
26+
}
27+
}

test/test-applications/integrations/TestApplication.GraphQL/Program.cs

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System.Collections;
5+
using TestApplication.Shared;
56

67
namespace TestApplication.GraphQL;
78

@@ -22,14 +23,7 @@ public static void Main(string[] args)
2223

2324
var logger = host.Services.GetRequiredService<ILogger<Program>>();
2425

25-
var prefixes = new[] { "COR_", "CORECLR_", "DOTNET_", "OTEL_" };
26-
var envVars = from envVar in Environment.GetEnvironmentVariables().Cast<DictionaryEntry>()
27-
from prefix in prefixes
28-
let key = (envVar.Key as string)?.ToUpperInvariant()
29-
let value = envVar.Value as string
30-
where key.StartsWith(prefix)
31-
orderby key
32-
select new KeyValuePair<string, string>(key, value);
26+
var envVars = ProfilerHelper.GetEnvironmentConfiguration();
3327

3428
foreach (var kvp in envVars)
3529
{

test/test-applications/integrations/TestApplication.GraphQL/StarWars/StarWarsSchema.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ public class StarWarsSchema : Schema
88
public StarWarsSchema(IServiceProvider provider)
99
: base(provider)
1010
{
11-
Query = provider.GetService(typeof(StarWarsQuery)) as StarWarsQuery ?? throw new InvalidOperationException();
12-
Mutation = provider.GetService(typeof(StarWarsMutation)) as StarWarsMutation ?? throw new InvalidOperationException();
13-
Subscription = provider.GetService(typeof(StarWarsSubscription)) as StarWarsSubscription ?? throw new InvalidOperationException();
11+
Query = provider.GetRequiredService<StarWarsQuery>();
12+
Mutation = provider.GetRequiredService<StarWarsMutation>();
13+
Subscription = provider.GetRequiredService<StarWarsSubscription>();
1414

1515
FieldMiddleware.Use(new InstrumentFieldsMiddleware());
1616
}

test/test-applications/integrations/TestApplication.GraphQL/Startup.cs

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using GraphQL;
5+
using GraphQL.SystemTextJson;
6+
using GraphQL.Transport;
57
using GraphQL.Types;
68
using StarWars;
79

@@ -21,6 +23,7 @@ public void ConfigureServices(IServiceCollection services)
2123

2224
public void Configure(IApplicationBuilder app)
2325
{
26+
app.UseMiddleware<CsrfMiddleware>();
2427
app.UseDeveloperExceptionPage();
2528
app.UseWebSockets();
2629
app.UseGraphQL<ISchema>();

tools/LibraryVersionsGenerator/PackageVersionDefinitions.cs

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ internal static class PackageVersionDefinitions
6666
Versions = new List<GraphQLVersion>
6767
{
6868
new("7.5.0") { MicrosoftDIVersion = "7.5.0", ServerTransportsAspNetCoreVersion = "7.5.0", ServerUIPlayground = "7.5.0" },
69+
new("8.0.2") { MicrosoftDIVersion = "8.0.2", ServerTransportsAspNetCoreVersion = "8.0.2", ServerUIPlayground = "8.0.2" },
6970
new("*") { MicrosoftDIVersion = "*", ServerTransportsAspNetCoreVersion = "*", ServerUIPlayground = "*" },
7071
}
7172
},

0 commit comments

Comments
 (0)