Skip to content

Commit

Permalink
WIP: Knex tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasboyt committed Jul 17, 2019
1 parent 018529a commit 3bb9f36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion api/src/models/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ENTRY_PAGE_LIMIT } from '../constants';
import { FeedSongItem, FeedItem, FeedMixtapeItem } from '../resources';
import { serializeSong, selectSongsQuery } from './song';
import validateOrThrow from '../util/validateOrThrow';
import traceQuery from '../util/traceQuery';

function serializeFeedSongItem(row: any): FeedSongItem {
return {
Expand Down Expand Up @@ -101,7 +102,7 @@ export async function getFeedByUserId(

query = query.limit(ENTRY_PAGE_LIMIT);

const rows = await query;
const rows = await traceQuery(query);

return rows.map(
(row: any): FeedItem => {
Expand Down
11 changes: 11 additions & 0 deletions api/src/util/traceQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as Knex from 'knex';
import { get as getAgent } from '@google-cloud/trace-agent';

export default function traceQuery(query: Knex.QueryBuilder): PromiseLike<any> {
const tracer = getAgent();
const span = tracer.createChildSpan({ name: 'knex' });

return query.finally(() => {
span.endSpan();
});
}

0 comments on commit 3bb9f36

Please sign in to comment.