Skip to content

Commit

Permalink
Renames Plugin Telemetry to Plugin Analytics (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleriva authored Mar 12, 2024
1 parent f3a60e1 commit 96ecc7f
Show file tree
Hide file tree
Showing 25 changed files with 607 additions and 205 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ Read the complete documentation at [https://docs.oramasearch.com](https://docs.o

- [Plugin Vitepress](https://docs.oramasearch.com/open-source/plugins/plugin-vitepress)
- [Plugin Docusaurus](https://docs.oramasearch.com/open-source/plugins/plugin-docusaurus)
- [Plugin Telemetry](https://docs.oramasearch.com/open-source/plugins/plugin-telemetry)
- [Plugin Analytics](https://docs.oramasearch.com/open-source/plugins/plugin-analytics)
- [Plugin Astro](https://docs.oramasearch.com/open-source/plugins/plugin-astro)
- [Plugin Data Persistence](https://docs.oramasearch.com/open-source/plugins/plugin-data-persistence)
- [Plugin Nextra](https://docs.oramasearch.com/open-source/plugins/plugin-nextra)
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default defineConfig({
{ text: 'Plugin Vitepress', link: '/open-source/plugins/plugin-vitepress.html' },
{ text: 'Plugin Docusaurus', link: '/open-source/plugins/plugin-docusaurus.html' },
{ text: 'Plugin Secure Proxy', link: '/open-source/plugins/plugin-secure-proxy.html' },
{ text: 'Plugin Telemetry', link: '/open-source/plugins/plugin-telemetry.html' },
{ text: 'Plugin Analytics', link: '/open-source/plugins/plugin-analytics.html' },
{ text: 'Plugin Astro', link: '/open-source/plugins/plugin-astro.html' },
{ text: 'Plugin Data Persistence', link: '/open-source/plugins/plugin-data-persistence.html' },
{ text: 'Plugin Match Highlight', link: '/open-source/plugins/plugin-match-highlight.html' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
outline: deep
---

# Plugin Telemetry
# Plugin Analytics

This plugin relies on [Orama Cloud](https://cloud.oramasearch.com) (free plan) and it's not available yet. Join our [slack channel](https://orama.to/slack) to get notified when it's ready.

Expand All @@ -12,19 +12,19 @@ This plugin relies on [Orama Cloud](https://cloud.oramasearch.com) (free plan) a
First of all, install it via npm (or any other package manager of your choice):

```sh
npm i @orama/plugin-telemetry
npm i @orama/plugin-analytics
```

Then, add it to your Orama configuration:

```js
import { Orama } from '@orama/core';
import { pluginTelemetry } from '@orama/plugin-telemetry';
import { pluginAnalytics } from '@orama/plugin-analytics';

const db = await create({
schema: { name: 'string' } as const,
plugins: [
pluginTelemetry({
pluginAnalytics({
apiKey: 'your-api-key',
indexId: 'your-index-id',
})
Expand All @@ -37,30 +37,30 @@ await insertMultiple(db, [
{ name: 'baz' },
])

// Collects telemetry data and sends it to Orama Cloud
// Collects anonymous analytics data and sends it to Orama Cloud
await search(db, { term: 'foo' })
```

## Disabling Telemetry
## Disabling Analytics

By default, Orama is shipped without telemetry plugin. If you want to enable it, you need to explicitly add it to your configuration as described above.
By default, Orama is shipped without analytics plugin. If you want to enable it, you need to explicitly add it to your configuration as described above.

Anyway, you can disable it by passing `enabled: false` to the `pluginTelemetry` function in your configuration, like this:
Anyway, you can disable it by passing `enabled: false` to the `pluginAnalytics` function in your configuration, like this:

```js
import { Orama } from '@orama/core';
import { pluginTelemetry } from '@orama/plugin-telemetry';
import { pluginAnalytics } from '@orama/plugin-analytics';

const db = await create({
schema: { name: 'string' } as const,
plugins: [
pluginTelemetry({
pluginAnalytics({
apiKey: 'your-api-key',
indexId: 'your-index-id',
enabled: false, // <--- disable telemetry
enabled: false, // <--- disable analytics
})
]
})
```

This flag is useful when you want to disable telemetry in development environment, for example.
This flag is useful when you want to disable analytics in development environment, for example.
2 changes: 1 addition & 1 deletion packages/orama/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ Read the complete documentation at [https://docs.oramasearch.com](https://docs.o

- [Plugin Vitepress](https://docs.oramasearch.com/open-source/plugins/plugin-vitepress)
- [Plugin Docusaurus](https://docs.oramasearch.com/open-source/plugins/plugin-docusaurus)
- [Plugin Telemetry](https://docs.oramasearch.com/open-source/plugins/plugin-telemetry)
- [Plugin Analytics](https://docs.oramasearch.com/open-source/plugins/plugin-analytics)
- [Plugin Astro](https://docs.oramasearch.com/open-source/plugins/plugin-astro)
- [Plugin Data Persistence](https://docs.oramasearch.com/open-source/plugins/plugin-data-persistence)
- [Plugin Nextra](https://docs.oramasearch.com/open-source/plugins/plugin-nextra)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# Orama Telemetry Plugin
# Orama Analytics Plugin

[![Tests](https://github.com/oramasearch/orama/actions/workflows/turbo.yml/badge.svg)](https://github.com/oramasearch/orama/actions/workflows/turbo.yml)

Official plugin to provide telemetry data on your searches.
Official plugin to provide analytics data on your searches.

# Usage

For the complete usage guide, please refer to the [official plugin documentation](https://docs.oramasearch.com/open-source/plugins/plugin-telemetry).
For the complete usage guide, please refer to the [official plugin documentation](https://docs.oramasearch.com/open-source/plugins/plugin-analytics).

To use the Orama Telemetry Plugin, you will need to sign up for a free account at [https://cloud.oramasearch.com](https://cloud.oramasearch.com)
To use the Orama Analytics Plugin, you will need to sign up for a free account at [https://cloud.oramasearch.com](https://cloud.oramasearch.com)

```js
import { create, insert, search } from '@orama/orama'
import { pluginTelemetry } from '@orama/plugin-telemetry'
import { pluginAnalytics} from '@orama/plugin-analytics'

const db = await create({
schema: {
title: 'string',
description: 'string'
},
plugins: [
pluginTelemetry({
pluginAnalytics({
apiKey: '<API-KEY>',
endpoint: '<ENDPOINT>'
})
]
})
```

For the full configuration guide of this plugin, please follow the [official plugin documentation](https://docs.oramasearch.com/open-source/plugins/plugin-telemetry).
For the full configuration guide of this plugin, please follow the [official plugin documentation](https://docs.oramasearch.com/open-source/plugins/plugin-analytics).

# License

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@orama/plugin-telemetry",
"name": "@orama/plugin-analytics",
"version": "2.0.9",
"description": "Orama plugin for providing telemetry data on your searches",
"description": "Orama plugin for providing analytics data on your searches",
"keywords": [
"orama",
"telemetry",
"analytics"
"analytics",
"telemetry"
],
"license": "Apache-2.0",
"main": "./dist/index.js",
Expand Down Expand Up @@ -47,7 +47,7 @@
"c8": "^7.12.0",
"msw": "^2.2.1",
"sinon": "^17.0.1",
"tap": "^18.6.1",
"tap": "^18.7.1",
"tap-mocha-reporter": "^5.0.3",
"tape": "^5.6.1",
"ts-standard": "^12.0.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { SearchEvent, TelemetryConfig } from './types.js'
import type { SearchEvent, AnalyticsConfig } from './types.js'
import { sendBeacon } from './polyfills.js'
import { TELEMETRY_OSS_SOURCE } from './const.js'
import { ANALYTICS_OSS_SOURCE } from './const.js'

type Data = object[]

export interface CollectorConstructor extends TelemetryConfig {
export interface CollectorConstructor extends AnalyticsConfig {
endpoint: string
apiKey: string
deploymentId: string
Expand Down Expand Up @@ -58,7 +58,7 @@ export class Collector {
this.data = []

const body = {
source: TELEMETRY_OSS_SOURCE,
source: ANALYTICS_OSS_SOURCE,
deploymentID: this.config.deploymentId,
index: this.config.indexId,
oramaId: this.config.oramaId,
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-analytics/src/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const DEFAULT_ANALYTICS_FLUSH_INTERVAL = 5000
export const DEFAULT_ANALYTICS_FLUSH_SIZE = 25
export const DEFAULT_ANALYTICS_ENDPOINT = 'https://telemetry.orama.run/oss_collect'
export const DEFAULT_ORAMA_DEPLOYMENT_ID = '-'
export const DEFAULT_ORAMA_VERSION = '-'
export const ANALYTICS_OSS_SOURCE = 'oss-fe'
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { AnyOrama, Results, SearchParams, OramaPluginSync, AnyDocument } from '@orama/orama'
import { Collector } from './collector.js'
import { DEFAULT_TELEMETRY_FLUSH_INTERVAL, DEFAULT_TELEMETRY_FLUSH_SIZE, DEFAULT_TELEMETRY_ENDPOINT, DEFAULT_ORAMA_DEPLOYMENT_ID, DEFAULT_ORAMA_VERSION } from './const.js'
import { DEFAULT_ANALYTICS_FLUSH_INTERVAL, DEFAULT_ANALYTICS_FLUSH_SIZE, DEFAULT_ANALYTICS_ENDPOINT, DEFAULT_ORAMA_DEPLOYMENT_ID, DEFAULT_ORAMA_VERSION } from './const.js'

const PLUGIN_NAME = 'plugin-telemetry'
const PLUGIN_NAME = 'plugin-analytics'

export interface PluginTelemetryParams {
export interface PluginAnalyticsParams {
apiKey: string
indexId: string
enabled?: boolean
Expand All @@ -15,20 +15,20 @@ export interface PluginTelemetryParams {
flushSize?: number
}

export function pluginTelemetry(params: PluginTelemetryParams) {
export function pluginAnalytics(params: PluginAnalyticsParams) {
if (params.enabled === false) {
// We register the plugin but we don't do anything
return {
name: PLUGIN_NAME
}
}

if (!params.apiKey) throw new Error('Missing apiKey for plugin-telemetry')
if (!params.indexId) throw new Error('Missing indexId for plugin-telemetry')
if (!params.apiKey) throw new Error('Missing apiKey for plugin-analytics')
if (!params.indexId) throw new Error('Missing indexId for plugin-analytics')

const flushInterval = params.flushInterval || DEFAULT_TELEMETRY_FLUSH_INTERVAL
const flushSize = params.flushSize || DEFAULT_TELEMETRY_FLUSH_SIZE
const endpoint = params.endpoint || DEFAULT_TELEMETRY_ENDPOINT
const flushInterval = params.flushInterval || DEFAULT_ANALYTICS_FLUSH_INTERVAL
const flushSize = params.flushSize || DEFAULT_ANALYTICS_FLUSH_SIZE
const endpoint = params.endpoint || DEFAULT_ANALYTICS_ENDPOINT
const deploymentId = params.deploymentId || DEFAULT_ORAMA_DEPLOYMENT_ID
let collector: Collector | undefined

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@ import { OramaPluginSync, create, insertMultiple, search } from '@orama/orama'
import { http, HttpResponse } from "msw";
import { setupServer, SetupServerApi } from "msw/node";

import { pluginTelemetry } from '../index.js'
import { pluginAnalytics } from '../index.js'
import { DEFAULT_ORAMA_DEPLOYMENT_ID } from '../const.js';

const FAKE_ENDPOINT = 'http://localhost:3000/sso_collect'
const API_KEY = 'the-api-key'
const INDEX_ID = 'the-index-id'

t.test('telemetry-plugin', async (t) => {
t.test('analytics-plugin', async (t) => {
const invocations: MockedRequest[] = []
const server = getServer(invocations)
await server.listen()
t.teardown(async () => {
await server.resetHandlers()
await server.close()

server.listen()

t.teardown(() => {
server.resetHandlers()
server.close()
})

const db = await create({
schema: { name: 'string' } as const,
plugins: [
pluginTelemetry({
pluginAnalytics({
apiKey: API_KEY,
indexId: INDEX_ID,
flushInterval: 100,
Expand Down Expand Up @@ -98,7 +100,7 @@ t.test('enabled: false', async (t) => {
const db = await create({
schema: { name: 'string' } as const,
plugins: [
pluginTelemetry({
pluginAnalytics({
apiKey: API_KEY,
indexId: INDEX_ID,
enabled: false
Expand All @@ -114,10 +116,10 @@ t.test('enabled: false', async (t) => {

t.test('throw error', async (t) => {
t.test('if apiKey is missing', async (t) => {
t.throws(() => pluginTelemetry({ indexId: 'a' } as any), /Missing apiKey for plugin-telemetry/)
t.throws(() => pluginAnalytics({ indexId: 'a' } as any), /Missing apiKey for plugin-analytics/)
})
t.test('if indexId is missing', async (t) => {
t.throws(() => pluginTelemetry({ apiKey: 'a' } as any), /Missing indexId for plugin-telemetry/)
t.throws(() => pluginAnalytics({ apiKey: 'a' } as any), /Missing indexId for plugin-analytics/)
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface SearchEvent {
cached?: boolean
}

export interface TelemetryConfig {
export interface AnalyticsConfig {
flushInterval: number
flushSize: number
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineConfig({
sourcemap: true,
minify: true,
format: ['cjs', 'esm', 'iife'],
globalName: 'pluginTelemetry',
globalName: 'pluginAnalytics',
dts: true,
clean: true,
bundle: true,
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-secure-proxy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export type SecureProxyPluginOptions = {
}

export async function pluginSecureProxy(pluginParams: SecureProxyPluginOptions): Promise<OramaPluginAsync> {
if (!pluginParams.apiKey) throw new Error('Missing "apiKey" parameter for plugin-telemetry')
if (!pluginParams.defaultProperty) throw new Error('Missing "defaultProperty" parameter for plugin-telemetry')
if (!pluginParams.model) throw new Error('Missing "model" parameter for plugin-telemetry')
if (!pluginParams.apiKey) throw new Error('Missing "apiKey" parameter for plugin-secure-proxy')
if (!pluginParams.defaultProperty) throw new Error('Missing "defaultProperty" parameter for plugin-secure-proxy')
if (!pluginParams.model) throw new Error('Missing "model" parameter for plugin-secure-proxy')

const proxy = new OramaProxy({
api_key: pluginParams.apiKey
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-secure-proxy/tsup.lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineConfig({
sourcemap: true,
minify: true,
format: ['cjs', 'esm', 'iife'],
globalName: 'pluginTelemetry',
globalName: 'pluginSecureProxy',
dts: true,
clean: true,
bundle: true,
Expand Down
6 changes: 0 additions & 6 deletions packages/plugin-telemetry/src/const.ts

This file was deleted.

5 changes: 5 additions & 0 deletions packages/tokenizers/scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import path from 'node:path'
import fs from 'node:fs'
import childProcess from 'node:child_process'

if (process.env.BUILD_TOKENIZERS !== '1') {
console.log('Skipping build for custom tokenizers.')
process.exit(0)
}

const isWasmPackInstalled = await checkWasmPackInstalled()

const languages = ['mandarin', 'japanese']
Expand Down
2 changes: 1 addition & 1 deletion packages/tokenizers/tests/japanese.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'
import t from 'tap'
import { create, insert, search } from '@orama/orama'

if (!fs.existsSync('build/tokenizer-japanese/tokenizer.js')) {
if (!fs.existsSync('build/tokenizer-japanese/tokenizer.js') && process.env.TEST_TOKENIZERS !== '1') {
// Still experimental. @todo: remove this check
console.log(`Skipping Japanese tokenizer tests`)
process.exit(0)
Expand Down
2 changes: 1 addition & 1 deletion packages/tokenizers/tests/mandarin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'
import t from 'tap'
import { create, insert, search } from '@orama/orama'

if (!fs.existsSync('build/tokenizer-mandarin/tokenizer.js')) {
if (!fs.existsSync('build/tokenizer-mandarin/tokenizer.js') && process.env.TEST_TOKENIZERS !== '1') {
// Still experimental. @todo: remove this check
console.log(`Skipping Mandarin tokenizer tests`)
process.exit(0)
Expand Down
Loading

0 comments on commit 96ecc7f

Please sign in to comment.