Skip to main content


HotChocolate OpenTelemetry

HotChocolate remains my favorite GraphQL client for .NET. As I find it really important to monitor my applications, I have written multiple posts (here and here ) on how to integrate monitoring with HotChocolate. At the beginning of this year, with the release of HotChocolate 12.5 , support for OpenTelemetry was introduced. Although I updated my applications to start using it, it took me until now to write a corresponding blog post about it. Instrument your GraphQL Server with OpenTelemetry Let me walk you through the steps: We’ll start with an ASP.NET Core application with OpenTelemetry enabled. Therefore we added the following NuGet packages: OpenTelemetry.Extensions.Hosting OpenTelemetry.Instrumentation.AspNetCore OpenTelemetry.Instrumentation.Http OpenTelemetry.Instrumentation.SqlClient We also add a reference to the AzureMonitor exporter because we want to use Application Insights: Azure.Monitor.OpenTelemetry.Exporter O
Recent posts

Convert a project to use centralised package management

If you have never heard about Central Package Management(CPM), first have a look at my blog post a few months ago. Done reading? Ok, we continue... To summarize, with CPM you bring all your dependencies in one place (the Directory.Packages.props file). This makes it easier to manage your dependencies for a large multiproject solution and helps you to avoid version drift where multiple versions of the same package are used inside your solution. Remark: CPM works both in Visual Studio and in JetBrains Rider . Convert your .NET solution to CPM manually If you want to start using CPM for your existing solutions, there are a few steps you need to repeat for every project inside your solution: Go through all of the csproj files and copy the references into the centralised Directory.Packages.props file Remove all the versions from the package reference entries in the csproj files. Although not that hard to do, it would be nice if this can be done automatically. Auto

Before re-usability comes usability

Reuse remains one of the holy grails in software architecture. How wonderful is life if we can write a piece of code(component, module, service, you name it...) only once and then start to use it everywhere? It is not surprising that I see a lot of IT managers and architects always play the 'reusability' card no matter the context. Reusability is important. Period! The risks of reusability As a consequence hours and hours are spend in meetings, design discussions, alignment sessions between stakeholders… to find out how we can make what we are trying to build reusable. This not only overcomplicates our designs but can also lead to gold plating(“What if this happens?”, “Maybe we will need that somewhere in the future?”). Another effect of this unhealthy addication to reuse is that it starts to hinder usability. By building a UI component, a piece of code or a data model in such a way that it becomes re-usable, it also becomes more ‘generic’ or ‘general purpose. My you

.NET 7 - The StringSyntaxAttribute

With the release of .NET 7, a new attribute was introduced; the StringSyntaxAttribute . What does the StringSyntaxAttribute do? The StringSyntaxAttribute allows you to tag strings. It can be applied to fields, properties, and parameters and provides tools like Visual Studio with information about the nature of the string. The compiler will use this information to provide the correct syntax highlighting: In this release following string formats can be used out of the box (and it is possible to create custom ones): CompositeFormat: The syntax identifier for strings containing composite formats for string formatting. DateOnlyFormat: The syntax identifier for strings containing date format specifiers. DateTimeFormat: The syntax identifier for strings containing date and time format specifiers. EnumFormat: The syntax identifier for strings containing Enum format specifiers. GuidFormat: The syntax identifier for strings containing Guid format specifiers. J

Url.ActionLink() is not thread-safe

I have an API that allows users to upload documents. To optimize the performance I save the documents to the database in parallel. After uploading has completed I return a list of URI's pointing to the document locations. Here is what the code looks like: As you can see in the code above, I combine a Task.WhenAll with a local function . Nothing special. However when I executed this code under high load, I started to get errors back from the API. A look at the logs, showed the following exception: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: chunkLength at System.Text.StringBuilder.ToString()   at Microsoft.AspNetCore.Mvc.Routing.UrlHelperBase.GenerateUrl(String protocol, String host, String path)   at Microsoft.AspNetCore.Mvc.Routing.EndpointRoutingUrlHelper.Action(UrlActionContext urlActionContext)   at Microsoft.AspNetCore.Mvc.UrlHelperExtensions.ActionLink(IUrlHelper helper, String action, String control

TDD, where did it all go wrong?

Every year, a new generation of developers start their career. And every year, I see these new developers struggling with writing tests. And if you dare to go one step further, and introduce them to Test Driven Development, they get even more confused. Don't misunderstand me, they are quite fast in understanding the mechanics of the testing frameworks(MsTest, Xunit, ...). But it turns out that is really hard to write good, maintainable tests that help to move forward instead of becoming a bottleneck. One of the reasons this is such a problem, is that what is now described as Test Driven Development is not aligned with the original intention. Ian Cooper has a great talk exactly about this issue: Ian Cooper reminds what was Kent's original proposition on TDD, what misunderstandings occurred along the way and suggests a better approach to TDD, one that supports development rather impeding it. There are 2 key elements of his talk, that I think are most important:

Using Event Counters with Application Insights

When adding the Application Insights SDK to your application, a set of Performance Counters is tracked by default. This is the list of default counters for ASP.NET web applications: % Process\Processor Time % Process\Processor Time Normalized Memory\Available Bytes ASP.NET Requests/Sec .NET CLR Exceptions Thrown / sec ASP.NET ApplicationsRequest Execution Time Process\Private Bytes Process\IO Data Bytes/sec ASP.NET Applications\Requests In Application Queue Processor(_Total)\% Processor Time However Performance Counters are a windows only feature. With .NET being cross-platform, is there a solution that works on both Windows and Linux? Of course there is! (Otherwise I wouldn’t be writing this blog post). Collecting EventCounters with Application Insights The documentation has the following to say about EventCounters: EventCounter is .NET/.NET Core mechanism to publish and consume counters or statistics. EventCounters are suppor