Skip to content

[LiveMetrics] add support for Logs#42889

Closed
TimothyMothra wants to merge 5 commits intomainfrom
tilee/livemetric_logs
Closed

[LiveMetrics] add support for Logs#42889
TimothyMothra wants to merge 5 commits intomainfrom
tilee/livemetric_logs

Conversation

@TimothyMothra
Copy link
Copy Markdown

@TimothyMothra TimothyMothra commented Mar 21, 2024

This PR adds functionality to collect logs and send to LiveMetrics as TraceDocuments.

Changes

  • Add new class LiveMetricsLogProcessor.cs with public method AddLiveMetrics.
  • Update Demo project to emit Logs
  • reintroduce ManagerFactory. This is the same pattern we use in the Exporter to have a single Transmitter for each signal.

Screenshot 2024-03-21 112337

return new Models.Trace()
{
DocumentType = DocumentIngressDocumentType.Trace,
Message = logRecord.FormattedMessage ?? logRecord.Body, // TODO: MAY NEED TO BUILD THE FORMATTED MESSAGE IF NOT AVAILABLE
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

FormattedMessage, if available, gives a string like "Hello World".
Body gives a string like "Hello {name}".

It seems that Application Insights would always build the fully formatted string. I don't think we should do that here. In a future PR, I think we could explore building a string that contains the template and the key-value-pairs. (ex: "Hello {name}. name: World").

I don't want to do this extra work until I have the unit test project up and working for this project. I propose leaving this as a TODO for now.

public Azure.Core.TokenCredential Credential { get { throw null; } set { } }
public bool EnableLiveMetrics { get { throw null; } set { } }
}
public static partial class LiveMetricsExtensions
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be an internal implementation and shouldn't be a new API.
Please mark this class and methods as internal.

namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models
{
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct DerivedMetricInfoAggregation : System.IEquatable<Azure.Monitor.OpenTelemetry.LiveMetrics.Models.DerivedMetricInfoAggregation>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this a public API?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This will go away.

Builds are currently failing because our api files are out of sync.
I'm addressing this in #42919

configure?.Invoke(options);

// INITIALIZE INTERNALS
var manager = ManagerFactory.Instance.Get(options);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should use ServiceCollections rather than getting an instance from singleton. This way we could avoid the complete ManagerFactory. Please note live metrics support is only available through distro.

builder.AddOpenTelemetry(options =>
{
//options.IncludeFormattedMessage = true;
options.AddLiveMetrics(configure => configure.ConnectionString = ConnectionString);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If this becomes internal, we don't need to parse options within the logging extensions. It should work in order where tracing initializes and logs utilizes it.

{
try
{
_manager.Dispose();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If manager is shared for the same options, what happens to others which are using this manager if you dispose one of them?

{
var key = options.ConnectionString ?? string.Empty;

if (!_runners.TryGetValue(key, out Manager? runner))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does it mean if a customer provides an empty connection string? Do we still continue in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants