Skip to content

[Getting Started] Add reference app specification #6820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

svrnm
Copy link
Member

@svrnm svrnm commented May 5, 2025

Contributes to the effort to rework our getting started guides

Signed-off-by: svrnm <sneumann@causely.ai>
@svrnm svrnm requested a review from a team as a code owner May 5, 2025 13:29
Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start! Thank you!

Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com>
Copy link
Contributor

@tiffany76 tiffany76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a quick copyedit first pass. Thanks!

svrnm and others added 3 commits June 5, 2025 10:37
Co-authored-by: Tiffany Hrabusa <30397949+tiffany76@users.noreply.github.com>
Signed-off-by: svrnm <sneumann@causely.ai>
@svrnm
Copy link
Member Author

svrnm commented Jun 5, 2025

Apologies for the delay! I took some time today to incorporate your reviews and expand on the details, please take a look!

Copy link
Contributor

@tiffany76 tiffany76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question, but otherwise LGTM.

svrnm and others added 2 commits June 18, 2025 11:01
Signed-off-by: svrnm <sneumann@causely.ai>
Comment on lines +55 to +57
- The code of the application must be split into two files:
- an `app` file that contains the handling of the HTTP requests
- a `lib` file that contains the implementation of the roll dice function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a hard requirement (must implies to me it is)? I get the argument for standardisation, but this is likely not idiomatic for a number of programming languages/frameworks (it's not for .NET/C#).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the thinking about this, is that we can demonstrate much better that if you have a library you only leverage the API and not the SDK. How is it not idiomatic for C# to put a functionality like that into a separate file? I would assume it works similar to java that you would create a Class that provides that functionality as service?

Copy link
Member

@martincostello martincostello Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By not idiomatic I mean files called app and lib. This reads as if it's mandating the file names.

If I were to write a simple idiomatic .NET application today to do a simple rolldice endpoint, I could do it like this in a single Program.cs file:

using System.Globalization;

var builder = WebApplication.CreateBuilder(args);

// Configure telemetry here, then...

var app = builder.Build();

app.MapGet("/rolldice/{player?}", (string? player, ILogger<Program> logger) =>
{
    var result = Random.Shared.Next(1, 7);

    if (string.IsNullOrEmpty(player))
    {
        logger.LogInformation("Anonymous player is rolling the dice: {result}", result);
    }
    else
    {
        logger.LogInformation("{player} is rolling the dice: {result}", player, result);
    }

    return result.ToString(CultureInfo.InvariantCulture);
});

app.Run();

This is essentially how we implemented rolldice in the .NET example in our grafana/docker-otel-lgtm repository.

If you still wanted the additional structure, then to be mostly-idiomatic you'd have something like this in .NET 6+:

- <App Directory>
|
|--> Program.cs - The entry-point to the application, needs to call and setup `App`.
|--> App.cs - The `App` class that sets up the webservice and defines the endpoints.
|--> Lib.cs - A weirdly-named (IMHO) class that provides the logic of the endpoint to roll the dice.
|--> Project.csproj - The project definition file.

With .NET 10, I could remove the need for the project file (Announcing dotnet run app.cs – A simpler way to start with C# and .NET 10) and at least change the name to app.cs, but I would still find lib.cs strange to find in a .NET project.

As the document is written right now, it seems overly-prescriptive to me. Rather, it would just talk about separating the HTTP handler code from the "business logic" as appropriate for the programming language/framework in question, rather than directing specific file names.

Copy link
Member Author

@svrnm svrnm Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not have to be "App.cs" or "Lib.cs" it can be something more meaningful in the context of your language.

The key point is that we separate the "library" that provides the dice rolling functionality from the "application" that consumes it. The business logic is super simple, that makes it awkward in most/all languages ... but it's here to demonstrate some concepts (separation of API & SDK, etc.)

So, if it makes more sense to call it "DiceRollService.cs" or "RollerMiddleware.cs" or whatever makes sense, and if "App.cs" is not necessary and it's functionality can be offloaded to "Program.cs" that's totally fine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, that basically fits with what I was getting at. I think the text as-written sounds like it's suggesting the files must be called that, rather than explaining what's wanted at a higher-level architectural/layout level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

5 participants