blob: 293fd40e9fb185abfc6759bcc1043c3f5cd8626d [file] [log] [blame]
Don Newton379ae252019-04-01 12:17:06 -04001// Copyright (C) MongoDB, Inc. 2017-present.
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may
4// not use this file except in compliance with the License. You may obtain
5// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
7package event
8
9import (
10 "context"
11
12 "github.com/mongodb/mongo-go-driver/bson"
13)
14
15// CommandStartedEvent represents an event generated when a command is sent to a server.
16type CommandStartedEvent struct {
17 Command bson.Raw
18 DatabaseName string
19 CommandName string
20 RequestID int64
21 ConnectionID string
22}
23
24// CommandFinishedEvent represents a generic command finishing.
25type CommandFinishedEvent struct {
26 DurationNanos int64
27 CommandName string
28 RequestID int64
29 ConnectionID string
30}
31
32// CommandSucceededEvent represents an event generated when a command's execution succeeds.
33type CommandSucceededEvent struct {
34 CommandFinishedEvent
35 Reply bson.Raw
36}
37
38// CommandFailedEvent represents an event generated when a command's execution fails.
39type CommandFailedEvent struct {
40 CommandFinishedEvent
41 Failure string
42}
43
44// CommandMonitor represents a monitor that is triggered for different events.
45type CommandMonitor struct {
46 Started func(context.Context, *CommandStartedEvent)
47 Succeeded func(context.Context, *CommandSucceededEvent)
48 Failed func(context.Context, *CommandFailedEvent)
49}