Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add support for synchronously flush #74

@jn011

Description

@jn011

Hi there,

I have recently tried to integrate with the new library in my serverless function which runs on .NET 6.

In Analytics.NET a call to Flush() would block the current thread and upload all events in the queue for a given client to Segment.

In Analytics-CSharp it seems that flush does not force upload events to segment?
Please checkout my reproduction code below and let me know if my usage is incorrect, in the old client this exact flow works perfectly. For this reason I have continued using Analytics .NET in my project for now.

using Segment.Analytics;
using Segment.Analytics.Utilities;

class SegmentLogger : ISegmentLogger
{
    public void Log(LogLevel logLevel, Exception exception = null, string message = null)
    {
        switch (logLevel)
        {
            case LogLevel.Warning:
            case LogLevel.Information:
            case LogLevel.Debug:
                Console.Out.WriteLine("Message: " + message);
                break;
            case LogLevel.Critical:
            case LogLevel.Trace:
            case LogLevel.Error:
                Console.Error.WriteLine("Exception: " + exception?.StackTrace);
                Console.Error.WriteLine("Message: " + message);
                break;
            case LogLevel.None:
            default:
                break;
        }
    }
}

internal class Program
{
    public static void Main(string[] args)
    {
        Analytics.Logger = new SegmentLogger();

        var analytics = new Analytics(new Configuration("__OMITTED__", storageProvider: new InMemoryStorageProvider()));

        var properties = new Dictionary<string, object?>
        {
            { "TesterProperty", "12345!" },
        };
    

        analytics.Track("dummy_event", properties);

        // Issue, flush does not upload to segment synchronously as expected
        analytics.Flush();
    }
}

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions