-
Notifications
You must be signed in to change notification settings - Fork 10
Closed
Description
Describe the bug
We are trying to use the enrichment closure for Track events. The incoming event is null IF the StartupQueue hasn't completed yet (meaning it'll replay it later). If I thread sleep for say a few seconds, then track the event, the enrichment closure is fire.
I believe this is because the startup plugin does not have the enrichment closure with it so when it plays it back it loses the original closure.
To Reproduce
Steps to reproduce the behavior:
- Start the Analytics with a config and immediately call Track with an enrichment closure
Expected behavior
The enrichment closure RawEvent is not null.
Platform (please complete the following information):
- Library Version in use: 2.5.1
- Platform being tested: Windows, Linux
- Integrations in use: N/A
Additional context
Track Call
var analyticsClient = scope.ServiceProvider.GetService<Analytics>();
// System.Threading.Thread.Sleep(5000); // This gives time for it to startup (no replay needed)
analyticsClient.Track(
"TestEvent",
properties,
(RawEvent evt) =>
{
evt.UserId = "12345"; // explodes if StartupQueue plugin stores an event for replay.
}
);
Scoped Configuration:
builder.Services.AddScoped<Analytics>(
(provider) =>
{
var config = new Configuration(
writeKey: builder.Configuration.GetSection("Segment")["WriteKey"],
storageProvider: new InMemoryStorageProvider(),
flushAt: 1,
eventPipelineProvider: new SyncEventPipelineProvider()
);
var analytics = new Analytics(config);
return analytics;
}
);
Stock Plugins Loaded:
Before - StartupQueue
Before - ContextPlugin
Destination - SegmentDestination
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
wenxi-zeng commentedon Apr 16, 2025
hi @richerm, thanks for reporting this issue. this is in our roadmap. will get back to you once we have a release for it.
richerm commentedon Apr 16, 2025
@wenxi-zeng - thanks - In the meantime is there a way I can check the 'state' or system status of the Analytics class? Basically I can block until it is 'ready'? This would save an arbitrary wait in code.
wenxi-zeng commentedon Apr 16, 2025
@richerm unfortunately no. the state is marked as internal. another workaround would be custom plugin. see this comment for example. not sure if that'd work for your use case though. I'll also try to escalate this issue.
richerm commentedon Apr 16, 2025
@wenxi-zeng Yes I saw that comment when searching earlier. Unfortunately, the enrichment I'm doing (in addition to user id) has contextual information and the serialize it to a property and to deserialize in a plugin and move to context is a pretty heavy workaround. Hopefully this gets addressed soon. In the meantime, I'm going to switch to a singleton model vs scoped with the caveats noted in the docs.
wenxi-zeng commentedon Apr 16, 2025
@richerm sounds good! I have prioritized a fix for this issue. should have a release out next monday.
wenxi-zeng commentedon Apr 23, 2025
hi @richerm, this issue should be fixed in the latest release
2.5.2
. please have a try. thanks!richerm commentedon Apr 28, 2025
Awesome! Thank-you for the quick turn-around!
richerm commentedon Apr 30, 2025
@wenxi-zeng
I received this error on writing to storage because the Enrichment property is marked as serializable. Is that expected behaviour?
The unsupported member type is located on type 'System.Func`2[Segment.Analytics.RawEvent,Segment.Analytics.RawEvent]'. Path: $.Enrichment.
wenxi-zeng commentedon Apr 30, 2025
hi @richerm, no, this is not expected. I just released a fix. please give
2.5.3
a try. you shouldn't see this error anymore