Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

Add @posthog/plugin-contrib and AWS SDK #306

Merged
merged 1 commit into from
Apr 12, 2021
Merged

Conversation

mariusandra
Copy link
Collaborator

Changes

Adds AWS SDK (needed for S3) and plugin contrib (needed for batching) for the plugin server.

With these in, a nice batched upload every 10MB would look like this:

import { createBuffer } from '@posthog/plugin-contrib'
import { S3 } from 'aws-sdk'

export function setupPlugin({ global }) {
    global.s3 = new S3(...)
    global.buffer = createBuffer({ limit: 10 * 1024 * 1024, timeoutSeconds: 10 * 60, onFlush: (batch) => {
        console.log(`Flushing ${batch.length} events!`)
        global.s3.upload(...)
    }})
}

export function teardownPlugin({ global }) {
    global.buffer.flush()
}

export function processEvent(event, { config, global }) {
    global.buffer.add(event, JSON.stringify(event).length) // add(object, points)
    return event
}

Checklist

  • Updated Settings section in README.md, if settings are affected
  • Jest tests

@mariusandra mariusandra added the bump patch Bump patch version when this PR gets merged label Apr 12, 2021
Copy link
Contributor

@yakkomajuri yakkomajuri 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 look at the buffer implementation - seems fine to me

Happy to cherry pick the version bump into the release

@yakkomajuri yakkomajuri merged commit b47050f into master Apr 12, 2021
@yakkomajuri yakkomajuri deleted the plugin-contrib branch April 12, 2021 12:54
fuziontech pushed a commit to PostHog/posthog that referenced this pull request Oct 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bump patch Bump patch version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants