Add more tracing

This commit is contained in:
Chocobozzz 2022-07-28 10:56:05 +02:00
parent 8224e13d3b
commit ce6b3765a2
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 28 additions and 2 deletions

View File

@ -149,6 +149,7 @@
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
"node-media-server": "^2.1.4", "node-media-server": "^2.1.4",
"nodemailer": "^6.0.0", "nodemailer": "^6.0.0",
"opentelemetry-instrumentation-sequelize": "^0.29.0",
"parse-torrent": "^9.1.0", "parse-torrent": "^9.1.0",
"password-generator": "^2.0.2", "password-generator": "^2.0.2",
"pg": "^8.2.1", "pg": "^8.2.1",

View File

@ -1,3 +1,4 @@
import { SequelizeInstrumentation } from 'opentelemetry-instrumentation-sequelize'
import { diag, DiagLogLevel, trace } from '@opentelemetry/api' import { diag, DiagLogLevel, trace } from '@opentelemetry/api'
import { JaegerExporter } from '@opentelemetry/exporter-jaeger' import { JaegerExporter } from '@opentelemetry/exporter-jaeger'
import { registerInstrumentations } from '@opentelemetry/instrumentation' import { registerInstrumentations } from '@opentelemetry/instrumentation'
@ -60,7 +61,8 @@ function registerOpentelemetryTracing () {
return [ cmdName, ...cmdArgs ].join(' ') return [ cmdName, ...cmdArgs ].join(' ')
} }
}), }),
new FsInstrumentation() new FsInstrumentation(),
new SequelizeInstrumentation()
] ]
}) })

View File

@ -1,5 +1,6 @@
import { generateMagnetUri } from '@server/helpers/webtorrent' import { generateMagnetUri } from '@server/helpers/webtorrent'
import { getActivityStreamDuration } from '@server/lib/activitypub/activity' import { getActivityStreamDuration } from '@server/lib/activitypub/activity'
import { tracer } from '@server/lib/opentelemetry/tracing'
import { getLocalVideoFileMetadataUrl } from '@server/lib/video-urls' import { getLocalVideoFileMetadataUrl } from '@server/lib/video-urls'
import { VideoViewsManager } from '@server/lib/views/video-views-manager' import { VideoViewsManager } from '@server/lib/views/video-views-manager'
import { uuidToShort } from '@shared/extra-utils' import { uuidToShort } from '@shared/extra-utils'
@ -71,6 +72,8 @@ function guessAdditionalAttributesFromQuery (query: VideosCommonQueryAfterSaniti
} }
function videoModelToFormattedJSON (video: MVideoFormattable, options: VideoFormattingJSONOptions = {}): Video { function videoModelToFormattedJSON (video: MVideoFormattable, options: VideoFormattingJSONOptions = {}): Video {
const span = tracer.startSpan('peertube.VideoModel.toFormattedJSON')
const userHistory = isArray(video.UserVideoHistories) ? video.UserVideoHistories[0] : undefined const userHistory = isArray(video.UserVideoHistories) ? video.UserVideoHistories[0] : undefined
const videoObject: Video = { const videoObject: Video = {
@ -168,10 +171,14 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options: VideoForm
videoObject.files = videoFilesModelToFormattedJSON(video, video.VideoFiles) videoObject.files = videoFilesModelToFormattedJSON(video, video.VideoFiles)
} }
span.end()
return videoObject return videoObject
} }
function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): VideoDetails { function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): VideoDetails {
const span = tracer.startSpan('peertube.VideoModel.toFormattedDetailsJSON')
const videoJSON = video.toFormattedJSON({ const videoJSON = video.toFormattedJSON({
additionalAttributes: { additionalAttributes: {
scheduledUpdate: true, scheduledUpdate: true,
@ -199,6 +206,8 @@ function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): Vid
trackerUrls: video.getTrackerUrls() trackerUrls: video.getTrackerUrls()
} }
span.end()
return Object.assign(videoJSON, detailsJSON) return Object.assign(videoJSON, detailsJSON)
} }

View File

@ -27,6 +27,7 @@ import {
import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video'
import { LiveManager } from '@server/lib/live/live-manager' import { LiveManager } from '@server/lib/live/live-manager'
import { removeHLSFileObjectStorage, removeHLSObjectStorage, removeWebTorrentObjectStorage } from '@server/lib/object-storage' import { removeHLSFileObjectStorage, removeHLSObjectStorage, removeWebTorrentObjectStorage } from '@server/lib/object-storage'
import { tracer } from '@server/lib/opentelemetry/tracing'
import { getHLSDirectory, getHLSRedundancyDirectory } from '@server/lib/paths' import { getHLSDirectory, getHLSRedundancyDirectory } from '@server/lib/paths'
import { VideoPathManager } from '@server/lib/video-path-manager' import { VideoPathManager } from '@server/lib/video-path-manager'
import { getServerActor } from '@server/models/application/application' import { getServerActor } from '@server/models/application/application'
@ -1535,6 +1536,8 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
options: BuildVideosListQueryOptions, options: BuildVideosListQueryOptions,
countVideos = true countVideos = true
): Promise<ResultList<VideoModel>> { ): Promise<ResultList<VideoModel>> {
const span = tracer.startSpan('peertube.VideoModel.getAvailableForApi')
function getCount () { function getCount () {
if (countVideos !== true) return Promise.resolve(undefined) if (countVideos !== true) return Promise.resolve(undefined)
@ -1554,6 +1557,8 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
const [ count, rows ] = await Promise.all([ getCount(), getModels() ]) const [ count, rows ] = await Promise.all([ getCount(), getModels() ])
span.end()
return { return {
data: rows, data: rows,
total: count total: count

View File

@ -1732,7 +1732,7 @@
semver "^7.3.2" semver "^7.3.2"
shimmer "^1.2.1" shimmer "^1.2.1"
"@opentelemetry/instrumentation@^0.29.2": "@opentelemetry/instrumentation@^0.29.0", "@opentelemetry/instrumentation@^0.29.2":
version "0.29.2" version "0.29.2"
resolved "https://registry.yarnpkg.com/@opentelemetry/instrumentation/-/instrumentation-0.29.2.tgz#70e6d4e1a84508f5e9d8c7c426adcd7b0dba6c95" resolved "https://registry.yarnpkg.com/@opentelemetry/instrumentation/-/instrumentation-0.29.2.tgz#70e6d4e1a84508f5e9d8c7c426adcd7b0dba6c95"
integrity sha512-LXx5V0ONNATQFCE8C5uqnxWSm4rcXLssdLHdXjtGdxRmURqj/JO8jYefqXCD0LzsqEQ6yxOx2GZ0dgXvhBVdTw== integrity sha512-LXx5V0ONNATQFCE8C5uqnxWSm4rcXLssdLHdXjtGdxRmURqj/JO8jYefqXCD0LzsqEQ6yxOx2GZ0dgXvhBVdTw==
@ -7027,6 +7027,15 @@ open@7:
is-docker "^2.0.0" is-docker "^2.0.0"
is-wsl "^2.1.1" is-wsl "^2.1.1"
opentelemetry-instrumentation-sequelize@^0.29.0:
version "0.29.0"
resolved "https://registry.yarnpkg.com/opentelemetry-instrumentation-sequelize/-/opentelemetry-instrumentation-sequelize-0.29.0.tgz#d8355b7c845473b3d66978b80620dba6f686e257"
integrity sha512-nBhWMhpOtFxR0+W9WwTC+g49UMPqDMusbceGycDJOaq9l7B/IGo8a15UHKm4N4uU/Cr1NTrvyJ0cFXUtSh7i3g==
dependencies:
"@opentelemetry/core" "^1.0.0"
"@opentelemetry/instrumentation" "^0.29.0"
"@opentelemetry/semantic-conventions" "^1.0.0"
opentracing@^0.14.4: opentracing@^0.14.4:
version "0.14.7" version "0.14.7"
resolved "https://registry.yarnpkg.com/opentracing/-/opentracing-0.14.7.tgz#25d472bd0296dc0b64d7b94cbc995219031428f5" resolved "https://registry.yarnpkg.com/opentracing/-/opentracing-0.14.7.tgz#25d472bd0296dc0b64d7b94cbc995219031428f5"