defineSkip registers an event and returns its definition. The argument skip is the number of stack frames to ascend, with 0 identifying the caller of defineSkip.
(name, description string, skip uint, opts ...Option)
| 103 | // defineSkip registers an event and returns its definition. |
| 104 | // The argument skip is the number of stack frames to ascend, with 0 identifying the caller of defineSkip. |
| 105 | func defineSkip(name, description string, skip uint, opts ...Option) Builder { |
| 106 | if definitions[name] != nil { |
| 107 | panic(fmt.Errorf("Event %q already defined", name)) |
| 108 | } |
| 109 | def := &definition{ |
| 110 | name: name, |
| 111 | description: description, |
| 112 | } |
| 113 | for _, opt := range opts { |
| 114 | if defOpt, ok := opt.(DefinitionOption); ok { |
| 115 | defOpt.applyToDefinition(def) |
| 116 | } |
| 117 | } |
| 118 | definitions[name] = def |
| 119 | |
| 120 | i18n.Define(fmt.Sprintf("%s:%s", i18nPrefix, name), description).SetSource(1 + skip) |
| 121 | initMetrics(name) |
| 122 | |
| 123 | var b Builder = def |
| 124 | if len(opts) > 0 { |
| 125 | b = b.With(opts...) |
| 126 | } |
| 127 | return b |
| 128 | } |
| 129 | |
| 130 | // Define a registered event. |
| 131 | func Define(name, description string, opts ...Option) Builder { |
no test coverage detected