This repository has been archived by the owner on Nov 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 520
Seq Extension #513
Merged
Merged
Seq Extension #513
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6b3dce8
Seq Extension
razfriman a9db9bf
Continue developement - add docs
razfriman e9e3c85
update docs
razfriman 5f8d8c6
Attempt to fix formatting
razfriman aca02c5
Formatting
razfriman 11f1daf
Fix bom
razfriman 35681ec
Remove binding name
jkotalik 3a20886
Some nits
jkotalik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Logging with Seq | ||
|
||
Seq is a popular log-aggregation system that gives you a powerful log search and dashboard engine with views across all of your services. | ||
|
||
Tye can push logs to Seq easily without the need for any SDKs or code changes in your services. | ||
|
||
## Getting started: running locally with Seq | ||
|
||
> :bulb: If you want an existing sample to run, the [sample here](https://github.com/dotnet/tye/tree/master/samples/frontend-backend) will do. This recipe will show examples of UI and data based on that sample. You own application will work fine, but the data and examples will look different. | ||
|
||
The first step is to add the `seq` extension to your `tye.yaml`. Add the `extensions` node and its children from the example below. | ||
|
||
```yaml | ||
name: frontend-backend | ||
|
||
extensions: | ||
- name: seq | ||
logPath: ./.logs | ||
|
||
services: | ||
- name: backend | ||
project: backend/backend.csproj | ||
- name: frontend | ||
project: frontend/frontend.csproj | ||
``` | ||
|
||
The `logPath` property here configures the path where Seq will store its data. | ||
|
||
Now launch the application with Tye: | ||
|
||
```sh | ||
tye run | ||
``` | ||
|
||
If you navigate to the Tye dashboard you should see an extra service (`seq`) in the list of services. | ||
|
||
|
||
<img width="1103" alt="image" src="https://user-images.githubusercontent.com/1769935/83251452-f26ffa00-a1ec-11ea-9642-29e4ec579178.png"> | ||
|
||
Visit the first URI (`http://localhost:5341`) in your browser to access the Seq dashboard. | ||
|
||
Now you're ready to view the data! After it loads, it should look like the screenshot below: | ||
|
||
<img width="1515" alt="image" src="https://user-images.githubusercontent.com/1769935/83251005-4cbc8b00-a1ec-11ea-9c76-b7e6db2ef73b.png"> | ||
|
||
Now you can see the logs from your application with each field broken out into structured format. If you take advantage of [structured logging](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1#log-message-template) then you'll see your own data included in structured form here alongside framework logs. | ||
|
||
It should like the screenshot below: | ||
|
||
<img width="1101" alt="image" src="https://user-images.githubusercontent.com/1769935/83252026-e46ea900-a1ed-11ea-9b96-38695c42dab4.png"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Tye.Extensions.Seq | ||
{ | ||
internal sealed class SeqExtension : Extension | ||
{ | ||
public override Task ProcessAsync(ExtensionContext context, ExtensionConfiguration config) | ||
{ | ||
if (context.Application.Services.Any(s => s.Name == "seq")) | ||
{ | ||
context.Output.WriteDebugLine("seq service already configured. Skipping..."); | ||
} | ||
else | ||
{ | ||
context.Output.WriteDebugLine("Injecting seq service..."); | ||
|
||
var seq = new ContainerServiceBuilder("seq", "datalust/seq") | ||
{ | ||
EnvironmentVariables = | ||
{ | ||
new EnvironmentVariableBuilder("ACCEPT_EULA") | ||
{ | ||
Value = "Y" | ||
}, | ||
}, | ||
Bindings = | ||
{ | ||
new BindingBuilder() | ||
{ | ||
Port = 5341, | ||
ContainerPort = 80, | ||
Protocol = "http", | ||
}, | ||
}, | ||
}; | ||
context.Application.Services.Add(seq); | ||
|
||
if (config.Data.TryGetValue("logPath", out var obj) && | ||
obj is string logPath && | ||
!string.IsNullOrEmpty(logPath)) | ||
{ | ||
seq.Volumes.Add(new VolumeBuilder(logPath, "seq-data", "/data")); | ||
} | ||
|
||
foreach (var s in context.Application.Services) | ||
{ | ||
if (object.ReferenceEquals(s, seq)) | ||
{ | ||
continue; | ||
} | ||
|
||
// make seq available as a dependency of everything. | ||
if (!s.Dependencies.Contains(seq.Name)) | ||
{ | ||
s.Dependencies.Add(seq.Name); | ||
} | ||
} | ||
} | ||
|
||
if (context.Operation == ExtensionContext.OperationKind.LocalRun) | ||
{ | ||
if (context.Options!.LoggingProvider is null) | ||
{ | ||
// For local development we hardcode the port and hostname | ||
context.Options.LoggingProvider = "seq=http://localhost:5341"; | ||
} | ||
} | ||
else if (context.Operation == ExtensionContext.OperationKind.Deploy) | ||
{ | ||
foreach (var project in context.Application.Services.OfType<DotnetProjectServiceBuilder>()) | ||
{ | ||
var sidecar = DiagnosticAgent.GetOrAddSidecar(project); | ||
|
||
// Use service discovery to find seq | ||
sidecar.Args.Add("--provider:seq=service:seq"); | ||
sidecar.Dependencies.Add("seq"); | ||
} | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn’t find much information on how this sidecar is implemented. (Maybe the code is in the repository and I totally overlooked it?)
However, I followed the existing patterns from the Elastic extensions and the logs did indeed get pushed into Seq.
—-
I did test this using the Frontend-backend example and that is how I provided the screenshots.
I will have a 2nd look to see if I can write up some sort of test to verify more of this functionality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should match up with the provider here:
https://github.com/dotnet/tye/blob/master/src/Microsoft.Tye.Hosting.Diagnostics/DiagnosticsProvider.cs#L17
https://github.com/dotnet/tye/blob/master/src/Microsoft.Tye.Hosting.Diagnostics/LoggingSink.cs#L199-L209
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you deploy and see if it worked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't have a Kubernetes cluster set up (locally or cloud). Is there any other way to test to see if this works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not today, we don't support other deployment targets nor do we have CI tests which run with kubernetes. We are working on getting some of that bootstrapped soon.
See https://github.com/dotnet/tye/blob/master/docs/tutorials/hello-tye/01_deploy.md#getting-started-with-deployment for some guidance on how to a cluster setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code for the sidecar is here if you want to peep it: https://github.com/dotnet/tye/tree/master/src/tye-diag-agent