Skip to content

Commit

Permalink
Trace CoreAPI.{upsert, getDocuments} (#1863)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasryaric authored Sep 28, 2023
1 parent 55f54af commit 111075b
Showing 1 changed file with 49 additions and 25 deletions.
74 changes: 49 additions & 25 deletions front/lib/core_api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import tracer from "dd-trace";
import { createParser } from "eventsource-parser";

import { Err, Ok, Result } from "@app/lib/result";
Expand Down Expand Up @@ -526,14 +527,25 @@ export const CoreAPI = {
documents: CoreAPIDocument[];
}>
> {
const response = await fetch(
`${CORE_API}/projects/${projectId}/data_sources/${dataSourceName}/documents?limit=${limit}&offset=${offset}`,
{
method: "GET",
return await tracer.trace(
`CoreAPI`,
{ resource: "getDataSourceDocuments" },
async (span) => {
if (span) {
span.setTag("projectId", projectId);
span.setTag("dataSourceName", dataSourceName);
span.setTag("limit", limit);
span.setTag("offset", offset);
}
const response = await fetch(
`${CORE_API}/projects/${projectId}/data_sources/${dataSourceName}/documents?limit=${limit}&offset=${offset}`,
{
method: "GET",
}
);
return _resultFromResponse(response);
}
);

return _resultFromResponse(response);
},

async getDataSourceDocument({
Expand Down Expand Up @@ -640,27 +652,39 @@ export const CoreAPI = {
data_source: CoreAPIDataSource;
}>
> {
const response = await fetch(
`${CORE_API}/projects/${projectId}/data_sources/${dataSourceName}/documents`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
document_id: documentId,
timestamp,
text,
tags,
parents,
source_url: sourceUrl,
credentials,
light_document_output: lightDocumentOutput,
}),
return await tracer.trace(
`CoreAPI`,
{ resource: "upsertDataSourceDocument" },
async (span) => {
if (span) {
span.setTag("projectId", projectId);
span.setTag("dataSourceName", dataSourceName);
span.setTag("documentId", documentId);
}

const response = await fetch(
`${CORE_API}/projects/${projectId}/data_sources/${dataSourceName}/documents`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
document_id: documentId,
timestamp,
text,
tags,
parents,
source_url: sourceUrl,
credentials,
light_document_output: lightDocumentOutput,
}),
}
);

return _resultFromResponse(response);
}
);

return _resultFromResponse(response);
},

async updateDataSourceDocumentTags({
Expand Down

0 comments on commit 111075b

Please sign in to comment.