npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@arizeai/openinference-core

v1.0.0

Published

OpenInference Core provides utilities shared by all OpenInference SDK packages.

Downloads

16,420

Readme

OpenInference Core

npm version

This package provides OpenInference Core utilities for LLM Traces.

Installation

npm install @arizeai/openinference-core # npm
pnpm add @arizeai/openinference-core # pnpm
yarn add @arizeai/openinference-core # yarn

Customizing Spans

The @arizeai/openinference-core package offers utilities to track important application metadata such as sessions and users using context attribute propagation:

  • setSession: to specify a session ID to track and group multi-turn conversations
  • setUser: to specify a user ID to track different conversations with a given user
  • setMetadata: to add custom metadata that can provide extra information to support a wide range of operational needs
  • setTag: to add tags, to filter spans on specific keywords
  • setPromptTemplate: to reflect the prompt template used, with its version and variables. This is useful for prompt template tracking
  • setAttributes: to add multiple custom attributes at the same time

[!NOTE] All @arizeai/openinference auto instrumentation packages will pull attributes off of context and add them to spans

Examples

setSession

import { context } from "@opentelemetry/api";
import { setSession } from "@arizeai/openinference-core";

context.with(setSession(context.active(), { sessionId: "session-id" }), () => {
  // Calls within this block will generate spans with the attributes:
  // "session.id" = "session-id"
});

Each setter function returns a new active context, so they can be chained together.

import { context } from "@opentelemetry/api";
import { setAttributes, setSession } from "@arizeai/openinference-core";

context.with(
  setAttributes(setSession(context.active(), { sessionId: "session-id" }), {
    myAttribute: "test",
  }),
  () => {
    // Calls within this block will generate spans with the attributes:
    // "myAttribute" = "test"
    // "session.id" = "session-id"
  },
);

Additionally, they can be used in conjunction with the OpenInference Semantic Conventions.

import { context } from "@opentelemetry/api"
import { setAttributes } from "@openinference-core"
import { SemanticConventions } from "@arizeai/openinference-semantic-conventions";


context.with(
  setAttributes(
    { [SemanticConventions.SESSION_ID: "session-id" }
  ),
  () => {
      // Calls within this block will generate spans with the attributes:
      // "session.id" = "session-id"
  }
)

If you are creating spans manually and want to propagate context attributes you've set to those spans as well you can use the getAttributesFromContext utility to do that. you can read more about customizing spans in our docs.

import { getAttributesFromContext } from "@arizeai/openinference-core";
import { context, trace } from "@opentelemetry/api";

const contextAttributes = getAttributesFromContext(context.active());
const tracer = trace.getTracer("example");
const span = tracer.startSpan("example span");
span.setAttributes(contextAttributes);
span.end();

Trace Config

This package also provides support for controlling settings like data privacy and payload sizes. For instance, you may want to keep sensitive information from being logged for security reasons, or you may want to limit the size of the base64 encoded images logged to reduced payload size.

[!NOTE] These values can also be controlled via environment variables, see more information here.

Here is an example of how to configure these settings using the OpenAI auto instrumentation. Note that all of our auto instrumentations will accept a traceConfig object.

import { OpenAIInstrumentation } from "@arizeai/openinference-instrumentation-openai";

/**
 * Everything left out of here will fallback to
 * environment variables then defaults
 */
const traceConfig = { hideInputs: true };

const instrumentation = new OpenAIInstrumentation({ traceConfig });